From 48993dd9f5fa1c0be4a0895735715a4b1c4b69d6 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 18 Mar 2024 09:21:42 -0400 Subject: [PATCH] Split locale enum, add duplicate values validation --- .../src/components/ChannelView/ChannelView.bs | 6 +- .../src/components/Dialog/LoginDialog.bs | 4 +- .../src/components/ProfileView/ProfileView.bs | 4 +- .../ProfileRowList/ProfileRowListCell.bs | 2 +- .../Screens/SearchScreen/SearchScreen.bs | 8 +- playlet-lib/src/source/utils/Locale.bs | 104 ++++++++++-------- tools/bs-plugins/locale-validation-plugin.ts | 15 +++ 7 files changed, 88 insertions(+), 55 deletions(-) diff --git a/playlet-lib/src/components/ChannelView/ChannelView.bs b/playlet-lib/src/components/ChannelView/ChannelView.bs index 14d55925..683a78f5 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.bs +++ b/playlet-lib/src/components/ChannelView/ChannelView.bs @@ -39,7 +39,7 @@ function OnNodeready() SetNavigation(m.rowList, "up", m.subscribeButton) SetNavigation(m.subscribeButton, "down", m.rowList) - m.subscribeButton.text = Tr(Locale.Subscribe) + m.subscribeButton.text = Tr(Locale.Buttons.Subscribe) DisposableObserveFieldScoped(m.subscribeButton, "buttonSelected", FuncName(OnSubscribeButtonSelected)) SetSubscribeButtonVisibility() @@ -300,9 +300,9 @@ end function function OnSubscriptionChanged() isSubbed = IsSubscribed() if isSubbed - m.subscribeButton.text = Tr(Locale.Unsubscribe) + m.subscribeButton.text = Tr(Locale.Buttons.Unsubscribe) else - m.subscribeButton.text = Tr(Locale.Subscribe) + m.subscribeButton.text = Tr(Locale.Buttons.Subscribe) end if end function diff --git a/playlet-lib/src/components/Dialog/LoginDialog.bs b/playlet-lib/src/components/Dialog/LoginDialog.bs index 9fdba243..bfe15aaa 100644 --- a/playlet-lib/src/components/Dialog/LoginDialog.bs +++ b/playlet-lib/src/components/Dialog/LoginDialog.bs @@ -12,7 +12,7 @@ function Init() m.top.observeFieldScoped("buttonSelected", FuncName(Close)) scanLabel = m.top.findNode("scanLabel") - scanLabel.text = Tr(Locale.ScanTheQrCode) + scanLabel.text = Tr(Locale.LoginDialog.ScanTheQrCode) end function function OnNodeReady() @@ -21,7 +21,7 @@ function OnNodeReady() if isValidAddress m.top.url = `${address}/invidious/login` else - m.urlLabel.text = Tr(Locale.IpAddressNotAvailable) + m.urlLabel.text = Tr(Locale.LoginDialog.IpAddressNotAvailable) end if m.invidious.observeFieldScoped("authToken", FuncName(OnAuthTokenChange)) diff --git a/playlet-lib/src/components/ProfileView/ProfileView.bs b/playlet-lib/src/components/ProfileView/ProfileView.bs index a235df20..e6a86ad9 100644 --- a/playlet-lib/src/components/ProfileView/ProfileView.bs +++ b/playlet-lib/src/components/ProfileView/ProfileView.bs @@ -144,10 +144,10 @@ function UpdateActivateButton() as void if m.activateButton.hasFocus() NodeSetFocus(m.logoutButton, true) end if - m.activateButton.text = Tr(Locale.InUse) + m.activateButton.text = Tr(Locale.Buttons.InUse) m.activateButton.disabled = true else - m.activateButton.text = Tr(Locale.Activate) + m.activateButton.text = Tr(Locale.Buttons.Activate) m.activateButton.disabled = false end if end function diff --git a/playlet-lib/src/components/Screens/ProfileScreen/ProfileRowList/ProfileRowListCell.bs b/playlet-lib/src/components/Screens/ProfileScreen/ProfileRowList/ProfileRowListCell.bs index 72fe04ce..a90cbb5a 100644 --- a/playlet-lib/src/components/Screens/ProfileScreen/ProfileRowList/ProfileRowListCell.bs +++ b/playlet-lib/src/components/Screens/ProfileScreen/ProfileRowList/ProfileRowListCell.bs @@ -17,7 +17,7 @@ function OnContentSet() as void ' bs:disable-next-line LINT3023 m.top.circlePosterInnerBlendColor = "#FFFFFFFF" m.top.letter = "" - m.top.username = Tr(Locale.Login) + m.top.username = Tr(Locale.Buttons.Login) m.top.serverUrl = "" m.top.crownVisible = false return diff --git a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs index 84fcb733..b9ead338 100644 --- a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs +++ b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs @@ -197,9 +197,9 @@ function OnFiltersChange() end if end for if filterCount > 0 - m.filtersButton.text = `${Tr(Locale.Filters)} (${filterCount})` + m.filtersButton.text = `${Tr(Locale.Buttons.Filters)} (${filterCount})` else - m.filtersButton.text = Tr(Locale.Filters) + m.filtersButton.text = Tr(Locale.Buttons.Filters) end if end function @@ -210,7 +210,7 @@ function Search(text as string) feedSource = { "id": `inv_search_${CryptoUtils.GetMd5(text)}` - "title": `${Tr(Locale.Search)} - ${text}` + "title": `${Tr(Locale.NavBar.Search)} - ${text}` "apiType": "Invidious" "endpoint": "search" "queryParams": { @@ -232,7 +232,7 @@ function Search(text as string) end for m.rowList.feeds = [{ - "title": `${Tr(Locale.Search)} - ${text}` + "title": `${Tr(Locale.NavBar.Search)} - ${text}` "feedSources": [feedSource] }] end function diff --git a/playlet-lib/src/source/utils/Locale.bs b/playlet-lib/src/source/utils/Locale.bs index 9030cb38..52fce800 100644 --- a/playlet-lib/src/source/utils/Locale.bs +++ b/playlet-lib/src/source/utils/Locale.bs @@ -1,43 +1,61 @@ -@locale -enum Locale - Profile = "Profile" - Search = "Search" - Home = "Home" - Bookmarks = "Bookmarks" - Settings = "Settings" - Remote = "Remote" - Info = "Info" - Activate = "Activate" - InUse = "In Use" - Login = "Login" - Logout = "Logout" - Close = "Close" - Filters = "Filters" - Subscriptions = "Subscriptions" - Playlists = "Playlists" - WatchHistory = "Watch history" - Trending = "Trending" - TrendingMovies = "Trending - Movies" - TrendingMusic = "Trending - Music" - TrendingGaming = "Trending - Gaming" - Popular = "Popular" - Videos = "Videos" - Shorts = "Shorts" - Live = "Live" - Podcasts = "Podcasts" - Edit = "Edit" - Save = "Save" - TestInstance = "Test instance" - Subscribe = "Subscribe" - Unsubscribe = "Unsubscribe" - LoginToInvidious = "Login to Invidious" - IpAddressNotAvailable = "IP address not available" - ScanTheQrCode = "Scan the QR code" - LoginInstructions1 = "Login to Invidious in order to view Subscriptions, Playlists, and use the Watch history." - LoginInstructions2 = "Please note that an Invidious account is different from a YouTube account." - InvidiousCustomInstance = "Invidious custom instance" - InvidiousOr = "Or" - InvidiousPublicInstances = "Invidious public instances" - MoveUp = "Move up" - MoveDown = "Move down" -end enum +namespace Locale + @locale + enum NavBar + Profile = "Profile" + Search = "Search" + Home = "Home" + Bookmarks = "Bookmarks" + Settings = "Settings" + Remote = "Remote" + Info = "Info" + end enum + + @locale + enum Buttons + Activate = "Activate" + InUse = "In Use" + Login = "Login" + Logout = "Logout" + Close = "Close" + Filters = "Filters" + Edit = "Edit" + Save = "Save" + TestInstance = "Test instance" + Subscribe = "Subscribe" + Unsubscribe = "Unsubscribe" + MoveUp = "Move up" + MoveDown = "Move down" + end enum + + @locale + enum Feed + Subscriptions = "Subscriptions" + Playlists = "Playlists" + WatchHistory = "Watch history" + Trending = "Trending" + TrendingMovies = "Trending - Movies" + TrendingMusic = "Trending - Music" + TrendingGaming = "Trending - Gaming" + Popular = "Popular" + Videos = "Videos" + Shorts = "Shorts" + Live = "Live" + Podcasts = "Podcasts" + end enum + + @locale + enum LoginDialog + LoginToInvidious = "Login to Invidious" + IpAddressNotAvailable = "IP address not available" + ScanTheQrCode = "Scan the QR code" + LoginInstructions1 = "Login to Invidious in order to view Subscriptions, Playlists, and use the Watch history." + LoginInstructions2 = "Please note that an Invidious account is different from a YouTube account." + end enum + + @locale + enum InvidiousSettings + InvidiousCustomInstance = "Invidious custom instance" + InvidiousOr = "Or" + InvidiousPublicInstances = "Invidious public instances" + end enum +end namespace diff --git a/tools/bs-plugins/locale-validation-plugin.ts b/tools/bs-plugins/locale-validation-plugin.ts index 6801be9a..9fc500f5 100644 --- a/tools/bs-plugins/locale-validation-plugin.ts +++ b/tools/bs-plugins/locale-validation-plugin.ts @@ -114,6 +114,21 @@ export class LocaleValidationPlugin implements CompilerPlugin { return; } + const uniqueLocaleValues = Array.from(new Set(this.localeValues)); + if (uniqueLocaleValues.length !== this.localeValues.length) { + const duplicates = this.localeValues.filter((value, index) => this.localeValues.indexOf(value) !== index); + program.addDiagnostics([{ + file: this.enums[0].file, + range: { + start: { line: 0, character: 0 }, + end: { line: 0, character: 0 } + }, + message: `Duplicate values in locale enums: ${duplicates.join(', ')}`, + severity: DiagnosticSeverity.Error, + code: 'LOCALE_DUPLICATE_VALUES', + }]); + } + this.validateEnglishTranslations(program, this.localeValues, this.enums[0].file); const rootDir = program.options.rootDir!;