diff --git a/.vscode/settings.json b/.vscode/settings.json index 474d28ad..0f55d8f0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,7 @@ { + "files.associations": { + "**/locale/**/*.ts": "xml" + }, "brightscript.output.clearConsoleOnChannelStart": false, "brightscript.bsdk": "node_modules/brighterscript", "editor.formatOnSave": true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d24ef8d..ec930724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Context menu sort options for channel videos and playlists +- Started added localization and added French to some of the screens ### Changed diff --git a/config/bsconfig.base.jsonc b/config/bsconfig.base.jsonc index ce28c4ea..a35ca8de 100644 --- a/config/bsconfig.base.jsonc +++ b/config/bsconfig.base.jsonc @@ -46,6 +46,12 @@ "regex": "\\?[\\.|\\[|\\(|@]", "regexFlags": "ig", "message": "No optional chaning (var1?.property). Do a type check instead." + }, + { + "code": "NO_TRANSLATE_STRING_LITERAL", + "regex": "\\bTr\\s*\\(\\s*\"[^\\\"]*\"\\s*\\)", + "regexFlags": "ig", + "message": "Tr(\"String\") is not allowed. Use Tr(Locale.Key) instead." } ], "files": [ @@ -56,6 +62,7 @@ "!**/*.psd", "!**/*.svg", "!**/*.svg.meta.json5", + "locale/**", "config/**", "lib/**", "www/**", @@ -79,7 +86,8 @@ "../tools/bs-plugins/logger-plugin.ts", "../tools/bs-plugins/image-gen-plugin.ts", "../tools/bs-plugins/type-gen-plugin.ts", - "../tools/bs-plugins/web-server-plugin.ts" + "../tools/bs-plugins/web-server-plugin.ts", + "../tools/bs-plugins/locale-validation-plugin.ts" ], "retainStagingDir": true, "require": [ diff --git a/config/bsconfig.tests.base.jsonc b/config/bsconfig.tests.base.jsonc index 8f3d9905..06bda329 100644 --- a/config/bsconfig.tests.base.jsonc +++ b/config/bsconfig.tests.base.jsonc @@ -8,6 +8,7 @@ "!**/*.psd", "!**/*.svg", "!**/*.svg.meta.json5", + "locale/**", "config/**", "lib/**", "www/**", @@ -29,7 +30,8 @@ "../tools/bs-plugins/logger-plugin.ts", "../tools/bs-plugins/image-gen-plugin.ts", "../tools/bs-plugins/type-gen-plugin.ts", - "../tools/bs-plugins/web-server-plugin.ts" + "../tools/bs-plugins/web-server-plugin.ts", + "../tools/bs-plugins/locale-validation-plugin.ts" ], "rooibos": { "logLevel": 2, diff --git a/docs/plugins.md b/docs/plugins.md index 747db02f..d09daade 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -12,6 +12,7 @@ - [Logger](#logger) - [Type Gen](#type-gen) - [Web Server](#web-server) +- [Locale validation](#locale-validation) Playlet implements a few [Brighterscript Plugins](https://github.com/rokucommunity/brighterscript/blob/master/docs/plugins.md). The plugins inject themselves in the compilation process, allowing the modification of bs scripts, xml components, and even assets or the app manifest. Let's start with a simple one: @@ -602,3 +603,23 @@ There one special annotation, and one special route: - `*` matches all paths So `@all(*)` would be a middleware that will be matched with any request. + +## Locale validation + +**[Source](/tools/bs-plugins/locale-validation-plugin.ts)** + +### Why + +Roku's built-in localization system has some undesired side effects: for example, it might translate node ids, which would break the relationship between the nodes. +This plugin enforces some rules to ensure translation files are kept up to date with code implementation. +See the next section for the validation rules. + +### How + +The plugin checks for the following: + +- Translated words and sentenses are defined in an enum annotated with `@locale` +- All the values in the `@locale` enums must be provided in the English (`en_US`) translation. This is because `en_US` is the fallback translation when the current localte translations are not complete. +- `en_US` must have matching source and translation values, so it can act as a fallback translation. +- All `source` translations from all languages must be present in the `@locale` enums. This is to prevent renaming the values in the code without updating translation files. +- Translation `source` keys can't be used except for certain fields such as `"text"` and `"title"`. This is to prevent the accidental localization of non-display fields, such as node ids. diff --git a/playlet-lib/src/components/ChannelView/ChannelView.bs b/playlet-lib/src/components/ChannelView/ChannelView.bs index c285f03b..14d55925 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.bs +++ b/playlet-lib/src/components/ChannelView/ChannelView.bs @@ -5,6 +5,7 @@ import "pkg:/source/AsyncTask/AsyncTask.bs" import "pkg:/source/AsyncTask/Tasks.bs" import "pkg:/source/utils/DisposableObserve.bs" import "pkg:/source/utils/FocusManagement.bs" +import "pkg:/source/utils/Locale.bs" import "pkg:/source/utils/Logging.bs" import "pkg:/source/utils/StringUtils.bs" import "pkg:/source/utils/Types.bs" @@ -38,7 +39,7 @@ function OnNodeready() SetNavigation(m.rowList, "up", m.subscribeButton) SetNavigation(m.subscribeButton, "down", m.rowList) - m.subscribeButton.text = "Subscribe" + m.subscribeButton.text = Tr(Locale.Subscribe) DisposableObserveFieldScoped(m.subscribeButton, "buttonSelected", FuncName(OnSubscribeButtonSelected)) SetSubscribeButtonVisibility() @@ -234,7 +235,7 @@ function GetContextMenuOptionsForItem(video as object) as object if StringUtils.IsNullOrEmpty(m.top.authorId) return [] end if - options = m.bookmarks@.GetMenuForChannel(m.top.content) + options = m.bookmarksService@.GetMenuForChannel(m.top.content) options.Append(GetSortingContextMenuOptionsForItem(video)) return options end function @@ -299,9 +300,9 @@ end function function OnSubscriptionChanged() isSubbed = IsSubscribed() if isSubbed - m.subscribeButton.text = "Unsubscribe" + m.subscribeButton.text = Tr(Locale.Unsubscribe) else - m.subscribeButton.text = "Subscribe" + m.subscribeButton.text = Tr(Locale.Subscribe) end if end function diff --git a/playlet-lib/src/components/ChannelView/ChannelView.xml b/playlet-lib/src/components/ChannelView/ChannelView.xml index 97e50d2d..1ce40e90 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.xml +++ b/playlet-lib/src/components/ChannelView/ChannelView.xml @@ -4,7 +4,7 @@ - + diff --git a/playlet-lib/src/components/Dialog/LoginDialog.bs b/playlet-lib/src/components/Dialog/LoginDialog.bs index 921ae813..9fdba243 100644 --- a/playlet-lib/src/components/Dialog/LoginDialog.bs +++ b/playlet-lib/src/components/Dialog/LoginDialog.bs @@ -1,4 +1,5 @@ import "DialogPalette.bs" +import "pkg:/source/utils/Locale.bs" import "pkg:/source/utils/StringUtils.bs" import "pkg:/source/utils/Types.bs" @@ -9,6 +10,9 @@ function Init() m.top.width = "920" m.top.observeFieldScoped("buttonSelected", FuncName(Close)) + + scanLabel = m.top.findNode("scanLabel") + scanLabel.text = Tr(Locale.ScanTheQrCode) end function function OnNodeReady() @@ -17,7 +21,7 @@ function OnNodeReady() if isValidAddress m.top.url = `${address}/invidious/login` else - m.urlLabel.text = "No IP address found" + m.urlLabel.text = Tr(Locale.IpAddressNotAvailable) end if m.invidious.observeFieldScoped("authToken", FuncName(OnAuthTokenChange)) diff --git a/playlet-lib/src/components/Dialog/LoginDialog.xml b/playlet-lib/src/components/Dialog/LoginDialog.xml index 5d6661de..01cbf679 100644 --- a/playlet-lib/src/components/Dialog/LoginDialog.xml +++ b/playlet-lib/src/components/Dialog/LoginDialog.xml @@ -7,8 +7,8 @@ - + + @@ -20,6 +20,7 @@ extendToDialogEdge="false" showDivider="false">