From 42dadec020277e979d68df20953423b3c60bc6c2 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 22 Mar 2024 17:43:03 -0400 Subject: [PATCH] locale for web app (#334) * locale for web app * more translations * Rename profiles service to avoid locale conflict * More translation work * Lint fix --------- Co-authored-by: github-action linter --- docs/playlet-web-api.yml | 2 + .../ContentNode/ChannelContentNode.bs | 5 +- .../ContentNode/PlaylistContentNode.bs | 5 +- .../src/components/MainScene.transpiled.xml | 2 +- playlet-lib/src/components/MainScene.xml | 6 +- .../MainScene_bindings.transpiled.brs | 6 +- .../components/NavBar/ProfileIconButton.bs | 10 +- .../src/components/ProfileView/ProfileView.bs | 12 +- .../components/ProfileView/ProfileView.xml | 2 +- .../Screens/ProfileScreen/ProfileScreen.bs | 6 +- .../Screens/ProfileScreen/ProfileScreen.xml | 2 +- .../Screens/SearchScreen/SearchScreen.bs | 2 +- .../InvidiousPublicInstances.bs | 4 +- .../Services/Invidious/Invidious.xml | 2 +- .../Services/Invidious/InvidiousService.bs | 2 +- .../Services/LoungeService/LoungeApi.bs | 20 +-- .../ProfilesInvidiousUnregisterTokenTask.bs | 0 .../ProfilesService.bs} | 3 +- .../ProfilesService.xml} | 2 +- .../ProfilesVerifyTokensTask.bs | 10 +- .../VideoFeed/VideoRowListRowContentTask.bs | 2 +- .../Middleware/InvidiousRouter.bs | 2 +- .../Middleware/ProfilesRouter.bs | 2 +- .../Middleware/StateApiRouter.bs | 2 +- .../Web/PlayletWebServer/PlayletWebServer.bs | 1 + .../Web/PlayletWebServer/PlayletWebServer.xml | 2 +- playlet-lib/src/config/mime-types.json5 | 1 + playlet-lib/src/config/preferences.json5 | 6 +- playlet-lib/src/locale/en_US/translations.ts | 128 +++++++++++++++++- playlet-lib/src/locale/fr_CA/translations.ts | 126 ++++++++++++++++- .../src/source/services/ApplicationInfo.bs | 1 + playlet-lib/src/source/utils/Locale.bs | 39 +++++- playlet-lib/src/source/utils/LocaleUtils.bs | 26 +++- playlet-web/src/App.svelte | 2 + playlet-web/src/lib/Api/Locale.ts | 37 +++++ playlet-web/src/lib/Api/PlayletApi.ts | 5 + playlet-web/src/lib/BottomNavigation.svelte | 14 +- playlet-web/src/lib/LinkDragDrop.svelte | 11 +- playlet-web/src/lib/ProfilesDialog.svelte | 14 +- .../src/lib/Screens/BookmarksScreen.svelte | 13 +- playlet-web/src/lib/Screens/InfoScreen.svelte | 26 ++-- .../lib/Screens/Search/SearchFilters.svelte | 10 +- .../src/lib/Screens/SearchScreen.svelte | 6 +- .../SettingControls/BooleanControl.svelte | 6 +- .../ClearSearchHistoryControl.svelte | 12 +- .../EditHomeScreenControl.svelte | 15 +- .../SettingControls/NumberControl.svelte | 6 +- .../PlayletLibVersionControl.svelte | 27 ++-- .../SettingControls/RadioControl.svelte | 8 +- .../SettingControls/StringControl.svelte | 15 +- .../lib/Screens/Settings/SettingsNode.svelte | 5 +- playlet-web/src/lib/Stores.ts | 2 + .../src/lib/VideoFeed/VideoListRow.svelte | 4 +- tools/bs-plugins/locale-validation-plugin.ts | 10 ++ 54 files changed, 538 insertions(+), 151 deletions(-) rename playlet-lib/src/components/Services/{Profiles => ProfilesService}/ProfilesInvidiousUnregisterTokenTask.bs (100%) rename playlet-lib/src/components/Services/{Profiles/Profiles.bs => ProfilesService/ProfilesService.bs} (99%) rename playlet-lib/src/components/Services/{Profiles/Profiles.xml => ProfilesService/ProfilesService.xml} (94%) rename playlet-lib/src/components/Services/{Profiles => ProfilesService}/ProfilesVerifyTokensTask.bs (67%) create mode 100644 playlet-web/src/lib/Api/Locale.ts diff --git a/docs/playlet-web-api.yml b/docs/playlet-web-api.yml index 8acc67f2..1866e1bf 100644 --- a/docs/playlet-web-api.yml +++ b/docs/playlet-web-api.yml @@ -572,6 +572,8 @@ components: type: string friendly_name: type: string + current_locale: + type: string invidious: type: object properties: diff --git a/playlet-lib/src/components/ContentNode/ChannelContentNode.bs b/playlet-lib/src/components/ContentNode/ChannelContentNode.bs index 2c3d80ec..92ad069d 100644 --- a/playlet-lib/src/components/ContentNode/ChannelContentNode.bs +++ b/playlet-lib/src/components/ContentNode/ChannelContentNode.bs @@ -3,6 +3,7 @@ import "pkg:/components/VideoFeed/FeedLoadState.bs" import "pkg:/source/AsyncTask/AsyncTask.bs" import "pkg:/source/AsyncTask/Tasks.bs" import "pkg:/source/utils/ErrorUtils.bs" +import "pkg:/source/utils/Locale.bs" import "pkg:/source/utils/Logging.bs" function LoadChannel(invidiousNode as object) as void @@ -39,8 +40,8 @@ function OnChannelContentTaskResult(output as object) as void error = ErrorUtils.Format(error) LogError(error) authorId = output.task.input.content.authorId - message = `Failed to load channel ${authorId}\n${error}` - DialogUtils.ShowDialog(message, "Channel load fail", true) + message = Tr(Locale.Dialogs.FailedToLoadChannel).Replace("%1", authorId) + `\n${error}` + DialogUtils.ShowDialog(message, Tr(Locale.Dialogs.ChannelLoadError), true) return end if end function diff --git a/playlet-lib/src/components/ContentNode/PlaylistContentNode.bs b/playlet-lib/src/components/ContentNode/PlaylistContentNode.bs index aee5ccb1..c35f2bee 100644 --- a/playlet-lib/src/components/ContentNode/PlaylistContentNode.bs +++ b/playlet-lib/src/components/ContentNode/PlaylistContentNode.bs @@ -3,6 +3,7 @@ import "pkg:/components/VideoFeed/FeedLoadState.bs" import "pkg:/source/AsyncTask/AsyncTask.bs" import "pkg:/source/AsyncTask/Tasks.bs" import "pkg:/source/utils/ErrorUtils.bs" +import "pkg:/source/utils/Locale.bs" import "pkg:/source/utils/Logging.bs" function LoadPlaylistPage(invidiousNode as object) as void @@ -48,8 +49,8 @@ function OnPlaylistContentTaskResult(output as object) as void error = ErrorUtils.Format(error) LogError(error) playlistId = output.task.input.content.playlistId - message = `Failed to load playlist ${playlistId}\n${error}` - DialogUtils.ShowDialog(message, "Playlist load fail", true) + message = Tr(Locale.Dialogs.FailedToLoadPlaylist).Replace("%1", playlistId) + `\n${error}` + DialogUtils.ShowDialog(message, Tr(Locale.Dialogs.PlaylistLoadError), true) return end if end function diff --git a/playlet-lib/src/components/MainScene.transpiled.xml b/playlet-lib/src/components/MainScene.transpiled.xml index d0ebc0cd..b39b0314 100644 --- a/playlet-lib/src/components/MainScene.transpiled.xml +++ b/playlet-lib/src/components/MainScene.transpiled.xml @@ -42,7 +42,7 @@ - + diff --git a/playlet-lib/src/components/MainScene.xml b/playlet-lib/src/components/MainScene.xml index ded79835..30b3af31 100644 --- a/playlet-lib/src/components/MainScene.xml +++ b/playlet-lib/src/components/MainScene.xml @@ -70,14 +70,14 @@ - + profilesService="bind:../ProfilesService" /> invalid - m.profiles = profiles - profiles.observeField("currentProfile", FuncName(OnCurrentProfile)) + profilesService = m.top.getScene().findNode("ProfilesService") + if profilesService <> invalid + m.profilesService = profilesService + profilesService.observeField("currentProfile", FuncName(OnCurrentProfile)) OnCurrentProfile() end if end function @@ -91,7 +91,7 @@ function onPaddingChanged() end function function OnCurrentProfile() as void - currentProfile = m.profiles.currentProfile + currentProfile = m.profilesService.currentProfile if currentProfile = invalid m.circlePoster.visible = false m.buttonIcon.visible = true diff --git a/playlet-lib/src/components/ProfileView/ProfileView.bs b/playlet-lib/src/components/ProfileView/ProfileView.bs index e6a86ad9..9845a3af 100644 --- a/playlet-lib/src/components/ProfileView/ProfileView.bs +++ b/playlet-lib/src/components/ProfileView/ProfileView.bs @@ -21,8 +21,8 @@ function OnNodeReady() SetNavigation(m.closeButton, "up", m.logoutButton) SetNavigation(m.logoutButton, "up", m.activateButton) - DisposableObserveFieldScoped(m.profiles, "currentProfile", FuncName(OnCunrrentProfileChanged)) - DisposableObserveFieldScoped(m.profiles, "onProfileLogout", FuncName(OnProfileLogout)) + DisposableObserveFieldScoped(m.profilesService, "currentProfile", FuncName(OnCunrrentProfileChanged)) + DisposableObserveFieldScoped(m.profilesService, "onProfileLogout", FuncName(OnProfileLogout)) end function function OnContentSet() as void @@ -81,13 +81,13 @@ function Activate() as void return end if - profile = m.profiles.content.getChild(0).findNode(content.id) + profile = m.profilesService.content.getChild(0).findNode(content.id) if profile = invalid return end if m.top.content = invalid - m.profiles@.SetCurrentProfile(profile) + m.profilesService@.SetCurrentProfile(profile) Close() end function @@ -98,7 +98,7 @@ function Logout() as void end if m.top.content = invalid - m.profiles@.LogoutWithProfile(content) + m.profilesService@.LogoutWithProfile(content) Close() end function @@ -127,7 +127,7 @@ function OnProfileLogout() as void return end if - profile = m.profiles.content.getChild(0).findNode(content.id) + profile = m.profilesService.content.getChild(0).findNode(content.id) if profile = invalid Close() end if diff --git a/playlet-lib/src/components/ProfileView/ProfileView.xml b/playlet-lib/src/components/ProfileView/ProfileView.xml index 95a4866a..778cbf27 100644 --- a/playlet-lib/src/components/ProfileView/ProfileView.xml +++ b/playlet-lib/src/components/ProfileView/ProfileView.xml @@ -9,7 +9,7 @@ - + - + diff --git a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs index b9ead338..dc467384 100644 --- a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs +++ b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs @@ -241,7 +241,7 @@ function OnSearchContentReady() as void m.rowlist.UnobserveFieldScoped("someContentReady") if not m.rowlist.someContentReady - DialogUtils.ShowDialog("We didn't find any results for your search. Please try again with a different query or different filters.", "No results found") + DialogUtils.ShowDialog(Tr(Locale.Dialogs.NoResultsFoundMessage), Tr(Locale.Dialogs.NoResultsFound)) m.rowlist.feeds = invalid m.rowlist.focusable = false HideLoadingScreen() diff --git a/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousPublicInstances/InvidiousPublicInstances.bs b/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousPublicInstances/InvidiousPublicInstances.bs index 8964205c..11148d3f 100644 --- a/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousPublicInstances/InvidiousPublicInstances.bs +++ b/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousPublicInstances/InvidiousPublicInstances.bs @@ -121,8 +121,8 @@ function OnInvidiousPublicInstancesTaskResults(output as object) as void error = ErrorUtils.Format(error) LogError(output.error) - message = `Failed to load Invidious public instances\n${error}` - DialogUtils.ShowDialog(message, "Invidious public instances load error", true) + message = Tr(Locale.Dialogs.FailedToLoadInvidiousPublicInstances) + `\n${error}` + DialogUtils.ShowDialog(message, Tr(Locale.Dialogs.InvidiousPublicInstancesLoadError), true) m.failedLabel.visible = true m.refreshButton.visible = true diff --git a/playlet-lib/src/components/Services/Invidious/Invidious.xml b/playlet-lib/src/components/Services/Invidious/Invidious.xml index 3c45dfdc..4f2def46 100644 --- a/playlet-lib/src/components/Services/Invidious/Invidious.xml +++ b/playlet-lib/src/components/Services/Invidious/Invidious.xml @@ -3,7 +3,7 @@ - + diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs index 6b2b1ae1..56f9b139 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs @@ -510,7 +510,7 @@ namespace Invidious end if LogInfo("Deleting Invidious token...") - m.invidiousNode.profiles@.LogoutWithAccessToken(authToken.token) + m.invidiousNode.profilesService@.LogoutWithAccessToken(authToken.token) end function function VerifyTokenScope(token as string) as boolean diff --git a/playlet-lib/src/components/Services/LoungeService/LoungeApi.bs b/playlet-lib/src/components/Services/LoungeService/LoungeApi.bs index 1f942df8..a8a9554b 100644 --- a/playlet-lib/src/components/Services/LoungeService/LoungeApi.bs +++ b/playlet-lib/src/components/Services/LoungeService/LoungeApi.bs @@ -102,17 +102,17 @@ class LoungeApi response = request.Await() if not response.IsSuccess() - error = `Failed to get screen id. Please restart playlet to use the cast function.\n${response.ErrorMessage()}` + error = Tr(Locale.Dialogs.LoungeFailedToGetScreenId) + `\n${response.ErrorMessage()}` LogError(error) - DialogUtils.ShowDialog(error, "Lounge service setup error") + DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError)) return invalid end if id = response.Text() if not IsString(id) - error = `Failed to get screen id. Please restart playlet to use the cast function.\nNot a valid screen id: ${id}` + error = Tr(Locale.Dialogs.LoungeFailedToGetScreenId) + `\n` = Tr(Locale.Dialogs.LoungeNotAValidScreenId).Replace("%1", `${id}`) LogError(error) - DialogUtils.ShowDialog(error, "Lounge service setup error") + DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError)) return invalid end if @@ -132,18 +132,18 @@ class LoungeApi response = request.Await() if not response.IsSuccess() - error = `Failed to get lounge token. Please restart playlet to use the cast function.\n${response.ErrorMessage()}` + error = Tr(Locale.Dialogs.LoungeFailedToGetLoungeToken) + `\n${response.ErrorMessage()}` LogError(error) - DialogUtils.ShowDialog(error, "Lounge service setup error") + DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError)) return invalid end if json = response.Json() screens = json.screens if not IsArray(screens) or screens.Count() <> 1 - error = `Failed to get lounge token. Please restart playlet to use the cast function.\nInvalid response: ${json}` + error = Tr(Locale.Dialogs.LoungeFailedToGetLoungeToken) + `\n` + Tr(Locale.Dialogs.LoungeInvalidResponse).Replace("%1", `${json}`) LogError(error) - DialogUtils.ShowDialog(error, "Lounge service setup error") + DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError)) return invalid end if @@ -178,9 +178,9 @@ class LoungeApi response = request.Await() if not response.IsSuccess() - error = `Failed to get session data. Please restart playlet to use the cast function.\n${response.ErrorMessage()}` + error = Tr(Locale.Dialogs.LoungeFailedToGetSessionData) + `\n${response.ErrorMessage()}` LogError(error) - DialogUtils.ShowDialog(error, "Lounge service setup error") + DialogUtils.ShowDialog(error, Tr(Locale.Dialogs.LoungeServiceSetupError)) return false end if diff --git a/playlet-lib/src/components/Services/Profiles/ProfilesInvidiousUnregisterTokenTask.bs b/playlet-lib/src/components/Services/ProfilesService/ProfilesInvidiousUnregisterTokenTask.bs similarity index 100% rename from playlet-lib/src/components/Services/Profiles/ProfilesInvidiousUnregisterTokenTask.bs rename to playlet-lib/src/components/Services/ProfilesService/ProfilesInvidiousUnregisterTokenTask.bs diff --git a/playlet-lib/src/components/Services/Profiles/Profiles.bs b/playlet-lib/src/components/Services/ProfilesService/ProfilesService.bs similarity index 99% rename from playlet-lib/src/components/Services/Profiles/Profiles.bs rename to playlet-lib/src/components/Services/ProfilesService/ProfilesService.bs index 0d1106b0..e97bdde0 100644 --- a/playlet-lib/src/components/Services/Profiles/Profiles.bs +++ b/playlet-lib/src/components/Services/ProfilesService/ProfilesService.bs @@ -73,7 +73,7 @@ function LoadProfilesFromRegistry() if profileNodes.Count() > 0 AsyncTask.Start(Tasks.ProfilesVerifyTokensTask, { - profiles: m.top + profilesService: m.top invidious: m.invidious profileNodes: profileNodes }) @@ -220,7 +220,6 @@ function LogoutWithProfile(profile as object) as void m.top.onProfileLogout = true AsyncTask.Start(Tasks.ProfilesInvidiousUnregisterTokenTask, { - profiles: m.top invidious: m.invidious profileNodes: [profile] }) diff --git a/playlet-lib/src/components/Services/Profiles/Profiles.xml b/playlet-lib/src/components/Services/ProfilesService/ProfilesService.xml similarity index 94% rename from playlet-lib/src/components/Services/Profiles/Profiles.xml rename to playlet-lib/src/components/Services/ProfilesService/ProfilesService.xml index 664c7fbc..0546a9a7 100644 --- a/playlet-lib/src/components/Services/Profiles/Profiles.xml +++ b/playlet-lib/src/components/Services/ProfilesService/ProfilesService.xml @@ -1,4 +1,4 @@ - + + {@html $tr(description).replace( + "$INVIDIOUS_PUBLIC_INSTANCES", + invidiousPublicInstancesLink + )} +
{#if inputValue !== currentValue} - + {/if}
diff --git a/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte b/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte index e1443209..0c94e58a 100644 --- a/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte +++ b/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte @@ -6,6 +6,7 @@ import RadioControl from "lib/Screens/Settings/SettingControls/RadioControl.svelte"; import StringControl from "lib/Screens/Settings/SettingControls/StringControl.svelte"; import NumberControl from "./SettingControls/NumberControl.svelte"; + import { tr } from "lib/Stores"; const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"]; @@ -53,8 +54,8 @@ /> {:else}
-
{displayText}
-
{description}
+
{$tr(displayText)}
+
{$tr(description)}
{/if} diff --git a/playlet-web/src/lib/Stores.ts b/playlet-web/src/lib/Stores.ts index cda0be34..58d0b43a 100644 --- a/playlet-web/src/lib/Stores.ts +++ b/playlet-web/src/lib/Stores.ts @@ -22,3 +22,5 @@ export const homeLayoutFileStore = writable([] as any); export const bookmarksStore = writable([] as any); export const searchHistoryStore = writable([] as any); + +export const tr = writable((s: string) => s as any); diff --git a/playlet-web/src/lib/VideoFeed/VideoListRow.svelte b/playlet-web/src/lib/VideoFeed/VideoListRow.svelte index 965eed70..0e816c95 100644 --- a/playlet-web/src/lib/VideoFeed/VideoListRow.svelte +++ b/playlet-web/src/lib/VideoFeed/VideoListRow.svelte @@ -1,6 +1,6 @@