[skip ci][tech debt] Fix localization plugin and missing items (#633)

* Fix localization plugin and missing items

* changelog fix

* Testing validation for config files
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2025-05-30 16:39:00 -04:00
1 parent 91081e09d5
commit d5f74d41c0
20 files changed
+219 -85

No files matched your search

+2 -1
View File
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Show videos watch progress in playlist view
- Missing localization in certain views
## [0.39.1] - 2025-05-23
@@ -760,7 +761,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
- Xmas theme logo - can't publish it before end of year... ([link](https://blog.roku.com/developer/channel-store-blackouts-2023))
- Xmas theme logo - can't publish it before end of year... ([channel-store-blackouts-2023](https://blog.roku.com/developer/channel-store-blackouts-2023))
## [0.17.3] - 2023-12-13
@@ -22,7 +22,7 @@
showDivider="false">
<Label
id="scanLabel"
text="Scan the QR Code"
text="Scan the QR code"
horizAlign="center"
wrap="true" width="400">
<Font role="font" uri="font:SystemFontFile" size="24" />
@@ -19,8 +19,9 @@ function Init()
m.top.observeFieldScoped("buttonSelected", FuncName(Close))
m.top.observeFieldScoped("wasClosed", FuncName(OnWasClosed))
scanLabel = m.top.findNode("scanLabel")
' TODO:P2 localize all dialog items
scanLabel.text = Tr(Locale.Dialogs.ScanTheQrCode)
linkInstructionLabel = m.top.findNode("linkInstructionLabel")
linkInstructionLabel.text = Tr(Locale.Dialogs.OpenLinkAndEnterFollowingCode).replace("%1", `'https://yt.be/activate'`)
end function
function OnNodeReady()
@@ -10,7 +10,8 @@
<StdDlgTitleArea primaryTitle="Login to YouTube" />
<StdDlgContentArea>
<StdDlgTextItem text="Open the link 'https://yt.be/activate' and enter the following code:" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<StdDlgTextItem id="linkInstructionLabel" text="Open the link 'https://yt.be/activate' and enter the following code:" />
<StdDlgTextItem id="codeLabel" text="Loading..." />
</StdDlgContentArea>
<StdDlgButtonArea id="buttonArea">
@@ -24,7 +25,7 @@
showDivider="false">
<Label
id="scanLabel"
text="Scan the QR Code"
text="Scan the QR code"
horizAlign="center"
wrap="true" width="400">
<Font role="font" uri="font:SystemFontFile" size="24" />
@@ -37,11 +38,11 @@
loadHeight="300"
padding="10"
translation="[50, 50]" />
<Label
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="https://yt.be/activate"
horizAlign="center"
width="400"
translation="[0, 380]"
text="https://yt.be/activate">
translation="[0, 380]">
<Font role="font" uri="font:MediumSystemFontFile" size="18" />
</Label>
</StdDlgSideCardArea>
+1 -2
View File
@@ -42,8 +42,7 @@
<AppVersionLabel
fontUri="font:BoldSystemFontFile"
fontSize="16"
translation="[0, 48]"
/>
translation="[0, 48]" />
</Poster>
<MarkupList
@@ -43,8 +43,7 @@
showRowLabel="[true]"
rowFocusAnimationStyle="floatingfocus"
variableWidthItems="true"
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png"
/>
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png" />
</Group>
</children>
</component>
@@ -36,7 +36,9 @@
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png">
<ContentNode role="content">
<ContentNode>
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<BackendTypeContentNode id="BackendTypeYouTube" title="YouTube" backendLogoUri="pkg:/images/youtube-logo.png" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<BackendTypeContentNode id="BackendTypeInvidious" title="Invidious" backendLogoUri="pkg:/images/invidious-logo.png" />
</ContentNode>
</ContentNode>
@@ -65,8 +65,7 @@
id="backendTypePoster"
width="60"
height="60"
translation="[110,110]"
/>
translation="[110,110]" />
</CirclePoster>
<Poster
id="CrownPoster"
@@ -81,13 +81,12 @@ function LoginWithInvidious() as void
end function
function ShowLoginWithYouTubeDialog() as void
' TODO:P2 localize
dialog = DialogUtils.ShowDialogEx({
title: "Disclaimer"
title: Tr(Locale.Dialogs.Disclaimer)
message: [
"Playlet is a third-party app and is not affiliated with, endorsed by, or sponsored by YouTube or Google. All trademarks and registered trademarks mentioned are the property of their respective owners and are used only for identification purposes."
"By using Playlet and signing in with your YouTube account, you acknowledge that you do so at your own risk. The developers of Playlet are not liable for any harm, including but not limited to data loss, account suspension or ban, hacking, or loss of content."
"Use responsibly, especially if your YouTube account is tied to business or monetization."
Tr(Locale.Dialogs.YouTubeLoginDisclaimer1)
Tr(Locale.Dialogs.YouTubeLoginDisclaimer2)
Tr(Locale.Dialogs.YouTubeLoginDisclaimer3)
]
large: true
buttons: [
@@ -52,8 +52,7 @@
id="backendTypePoster"
width="60"
height="60"
translation="[110,110]"
/>
translation="[110,110]" />
</CirclePoster>
<Poster
id="CrownPoster"
@@ -16,8 +16,7 @@
vertAlign="center"
text="Could not get IP address: are we connected to the internet?"
wrap="true"
translation="[145,0]"
/>
translation="[145,0]" />
</Group>
<Group id="yesInternet" visible="false">
<LayoutGroup
@@ -83,9 +82,9 @@
vertAlignment="center"
translation="[0,245]">
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="1." />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="1."
font="font:SmallSystemFont" />
<Label
font="font:SmallSystemFont"
width="380"
@@ -93,9 +92,9 @@
text="On your phone, connect to the same Wi-Fi network as this device." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="2." />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="2."
font="font:SmallSystemFont" />
<Label
font="font:SmallSystemFont"
width="380"
@@ -103,14 +102,14 @@
text="Open the YouTube app on your phone." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="3." />
<MultiStyleLabel
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="3."
font="font:SmallSystemFont" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<MultiStyleLabel text="Tap the cast icon and select this device."
id="WifiInstructionWithDeviceNameLabel"
width="380"
wrap="true"
text="Tap the cast icon and select this device." />
wrap="true" />
</LayoutGroup>
<Label
text="Roku connected to:"
@@ -131,9 +130,9 @@
vertAlignment="center"
translation="[0,245]">
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="1." />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="1."
font="font:SmallSystemFont" />
<Label
font="font:SmallSystemFont"
width="380"
@@ -141,9 +140,9 @@
text="On your phone, open the YouTube app." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="2." />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="2."
font="font:SmallSystemFont" />
<Label
font="font:SmallSystemFont"
width="380"
@@ -151,9 +150,9 @@
text="Tap the cast icon." />
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label
font="font:SmallSystemFont"
text="3." />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="3."
font="font:SmallSystemFont" />
<Label
font="font:SmallSystemFont"
width="380"
@@ -18,16 +18,14 @@
<DynamicMiniKeyboard
id="keyboard"
translation="[695,110]"
/>
translation="[695,110]" />
<ButtonGroup
id="suggestions"
focusable="false"
minWidth="400"
maxWidth="480"
buttonHeight="50"
translation="[125,100]"
/>
translation="[125,100]" />
<VideoRowList
itemComponentName="RowCell"
id="rowList"
@@ -43,8 +41,7 @@
showRowLabel="[true]"
rowFocusAnimationStyle="floatingfocus"
variableWidthItems="true"
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png"
/>
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png" />
<Animation
id="scrollAnimation"
duration="0.3">
@@ -10,7 +10,7 @@
translation="[380,96]" />
<Label
id="failedLabel"
text="Failed to load Invidious public instances."
text="Failed to load Invidious public instances"
horizAlign="center"
translation="[0,60]"
width="960" />
@@ -16,29 +16,29 @@
<Font role="font" uri="font:SystemFontFile" size="18" />
</Label>
<LayoutGroup layoutDirection="horiz">
<Button
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Button text="-"
id="MinusButton"
iconUri=""
focusedIconUri=""
minWidth="64"
maxWidth="64"
showFocusFootprint="true"
text="-" />
<Button
showFocusFootprint="true" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Button text="0"
id="NumberButton"
iconUri=""
focusedIconUri=""
minWidth="150"
showFocusFootprint="true"
text="0" />
<Button
showFocusFootprint="true" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Button text="+"
id="PlusButton"
iconUri=""
focusedIconUri=""
minWidth="64"
maxWidth="64"
showFocusFootprint="true"
text="+" />
showFocusFootprint="true" />
</LayoutGroup>
</children>
</component>
@@ -23,11 +23,17 @@
<ContentNode role="content">
<ContentNode id="auto" title="Auto" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="1080p" title="1080p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="720p" title="720p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="480p" title="480p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="360p" title="360p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="240p" title="240p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="144p" title="144p" />
</ContentNode>
</CheckList>
@@ -16,9 +16,9 @@
height="50"
translation="[10,10]">
</Poster>
<Label
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="..."
id="categoryLabel"
text="..."
font="font:SmallestBoldSystemFont"
lineSpacing="5"
horizAlign="center"
@@ -20,8 +20,8 @@
<function name="PlayWithContent" />
</interface>
<children>
<SimpleLabel
text="Dev Player!"
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<SimpleLabel text="Dev Player!"
color="#FF0000"
fontUri="font:SmallestBoldSystemFont"
horizOrigin="right"
@@ -264,6 +264,34 @@
<source>Failed to get session data. Please restart Playlet to use the cast function.</source>
<translation>Failed to get session data. Please restart Playlet to use the cast function.</translation>
</message>
<message>
<source>Select a service to login</source>
<translation>Select a service to login</translation>
</message>
<message>
<source>Login to YouTube</source>
<translation>Login to YouTube</translation>
</message>
<message>
<source>Open the link %1 and enter the following code:</source>
<translation>Open the link %1 and enter the following code:</translation>
</message>
<message>
<source>Disclaimer</source>
<translation>Disclaimer</translation>
</message>
<message>
<source>Playlet is a third-party app and is not affiliated with, endorsed by, or sponsored by YouTube or Google. All trademarks and registered trademarks mentioned are the property of their respective owners and are used only for identification purposes.</source>
<translation>Playlet is a third-party app and is not affiliated with, endorsed by, or sponsored by YouTube or Google. All trademarks and registered trademarks mentioned are the property of their respective owners and are used only for identification purposes.</translation>
</message>
<message>
<source>By using Playlet and signing in with your YouTube account, you acknowledge that you do so at your own risk. The developers of Playlet are not liable for any harm, including but not limited to data loss, account suspension or ban, hacking, or loss of content.</source>
<translation>By using Playlet and signing in with your YouTube account, you acknowledge that you do so at your own risk. The developers of Playlet are not liable for any harm, including but not limited to data loss, account suspension or ban, hacking, or loss of content.</translation>
</message>
<message>
<source>Use responsibly, especially if your YouTube account is tied to business or monetization.</source>
<translation>Use responsibly, especially if your YouTube account is tied to business or monetization.</translation>
</message>
<message>
<source>Invidious custom instance</source>
<translation>Invidious custom instance</translation>
+8
View File
@@ -86,6 +86,14 @@ namespace Locale
LoungeFailedToGetLoungeToken = "Failed to get lounge token. Please restart Playlet to use the cast function."
LoungeInvalidResponse = "Invalid response: %1"
LoungeFailedToGetSessionData = "Failed to get session data. Please restart Playlet to use the cast function."
' YouTube login
SelectServiceToLogin = "Select a service to login"
LoginToYouTube = "Login to YouTube"
OpenLinkAndEnterFollowingCode = "Open the link %1 and enter the following code:"
Disclaimer = "Disclaimer"
YouTubeLoginDisclaimer1 = "Playlet is a third-party app and is not affiliated with, endorsed by, or sponsored by YouTube or Google. All trademarks and registered trademarks mentioned are the property of their respective owners and are used only for identification purposes."
YouTubeLoginDisclaimer2 = "By using Playlet and signing in with your YouTube account, you acknowledge that you do so at your own risk. The developers of Playlet are not liable for any harm, including but not limited to data loss, account suspension or ban, hacking, or loss of content."
YouTubeLoginDisclaimer3 = "Use responsibly, especially if your YouTube account is tied to business or monetization."
end enum
@locale
+117 -21
View File
@@ -5,6 +5,7 @@
// 4. Xml components do not have values that can be translated by accident
// - an accidental translation can be a translated node id that's not supposed to be translated
// - For that reason, only certain attributes (like "text" and "title") are allowed to have localized values
// 5. Xml components with attributes that SHOULD be translated, are translated
import {
BrsFile,
@@ -19,13 +20,18 @@ import {
isBrsFile,
isXmlFile
} from "brighterscript";
import { existsSync, readFileSync } from "fs";
import { join as pathJoin } from "path";
import fs from "fs";
import path from "path";
import * as xml2js from 'xml2js';
import { globSync } from 'glob';
import { SGNode } from "brighterscript/dist/parser/SGTypes";
import json5 from 'json5';
import YAML from "yaml";
const allowedXmlAttributes = ["text", "title", "primaryTitle", "displayText", "description"];
const translatableXmlAttributes = ["text", "title", "short_title", "primaryTitle", "displayText", "description"];
const jsonExtensions = ['.json', '.jsonc', '.json5'];
const yamlExtensions = ['.yaml', '.yml'];
export class LocaleValidationPlugin implements CompilerPlugin {
public name = 'LocaleValidationPlugin';
@@ -44,6 +50,18 @@ export class LocaleValidationPlugin implements CompilerPlugin {
}
afterFileValidate(file: BscFile) {
// There isn't a great way to validate files outside of the program.
// We're just attaching diagnostics to known file (like "Locale.bs") which
// is too specific.
// Additinally, config files do contain a couple of translatable values
// that should be ignored, but there isn't a simple mechianim to do that.
// Config validation disabled for now.
//
// if (file.pkgPath == "source/utils/Locale.bs") {
// this.validateConfigFiles(file, file.program);
// return;
// }
if (!isXmlFile(file)) {
return;
}
@@ -64,7 +82,7 @@ export class LocaleValidationPlugin implements CompilerPlugin {
const value = field.value;
if (value && localeValues.includes(value)) {
const id = field.id;
if (!allowedXmlAttributes.includes(id)) {
if (!translatableXmlAttributes.includes(id)) {
file.addDiagnostics([{
file: file,
range: field.range!,
@@ -87,17 +105,32 @@ export class LocaleValidationPlugin implements CompilerPlugin {
validateSgNode(node: SGNode, localeValues: string[], file: XmlFile) {
node.attributes.forEach((attribute) => {
const value = attribute.value.text;
if (value && localeValues.includes(value)) {
const key = attribute.key.text;
if (!allowedXmlAttributes.includes(key)) {
file.addDiagnostics([{
file: file,
range: attribute.value.range!,
message: `Locale value found in xml component: "${value}" but the attribute "${key}" is not allowed to be localized.`,
severity: DiagnosticSeverity.Error,
code: 'LOCALE_VALUE_IN_XML',
}]);
}
if (!value) {
return;
}
const key = attribute.key.text;
const isKeyTranslatable = translatableXmlAttributes.includes(key)
const isValueTranslated = localeValues.includes(value)
if (isValueTranslated && !isKeyTranslatable) {
file.addDiagnostics([{
file: file,
range: attribute.value.range!,
message: `Locale value found in xml component: "${value}" but the attribute "${key}" is not allowed to be localized.`,
severity: DiagnosticSeverity.Error,
code: 'LOCALE_VALUE_IN_XML',
}]);
}
if (isKeyTranslatable && !isValueTranslated) {
file.addDiagnostics([{
file: file,
range: attribute.value.range!,
message: `The attribute "${key}" with value "${value}" should be localized, but not found in locale files.`,
severity: DiagnosticSeverity.Warning,
code: 'LOCALE_MISSING_TRANSLATIONS',
}]);
}
});
@@ -134,8 +167,8 @@ export class LocaleValidationPlugin implements CompilerPlugin {
const rootDir = program.options.rootDir!;
const translationFiles = globSync(`locale/**/translations.ts`, { cwd: rootDir });
translationFiles.forEach((translationFile) => {
const srcPath = pathJoin(rootDir, translationFile);
const pkgPath = pathJoin('pkg:/', translationFile);
const srcPath = path.join(rootDir, translationFile);
const pkgPath = path.join('pkg:/', translationFile);
const xmlFile = new XmlFile(srcPath, pkgPath, program);
this.validateTranslations(xmlFile, program, this.localeValues, this.enums[0].file);
});
@@ -164,8 +197,8 @@ export class LocaleValidationPlugin implements CompilerPlugin {
validateEnglishTranslations(program: Program, localeValues: string[], file: BrsFile) {
const translationFile = 'locale/en_US/translations.ts';
const srcPath = pathJoin(program.options.rootDir!, translationFile);
const pkgPath = pathJoin('pkg:/', translationFile);
const srcPath = path.join(program.options.rootDir!, translationFile);
const pkgPath = path.join('pkg:/', translationFile);
const xmlFile = new XmlFile(srcPath, pkgPath, program);
const englishTranslations = this.loadTranslationsFile(program, xmlFile);
@@ -216,10 +249,10 @@ export class LocaleValidationPlugin implements CompilerPlugin {
loadTranslationsFile(program: Program, translationFile: XmlFile) {
// load xml ts translation file
if (!existsSync(translationFile.srcPath)) {
if (!fs.existsSync(translationFile.srcPath)) {
return null;
}
const content = readFileSync(translationFile.srcPath, 'utf8');
const content = fs.readFileSync(translationFile.srcPath, 'utf8');
const xml = this.parseXml(content);
if (!xml || !xml.TS || !xml.TS.context || !xml.TS.context[0].message) {
return null;
@@ -318,6 +351,69 @@ export class LocaleValidationPlugin implements CompilerPlugin {
}
return false
}
validateConfigFiles(file: BscFile, program: Program) {
const extensions = [...jsonExtensions, ...yamlExtensions]
const rootDir = program.options.rootDir!;
const configFiles = globSync(`config/**`, { cwd: rootDir })
.filter(filePath => extensions.includes(path.extname(filePath)))
.map(filePath => path.join(rootDir, filePath));
const localeValues = this.localeValues;
configFiles.forEach(configFile => this.validateConfigFile(configFile, file, localeValues, program))
}
validateConfigFile(configFile: string, file: BscFile, localeValues: string[], program: Program) {
const configData = this.parseConfigFile(configFile);
this.validateConfigData(configData, configFile, file, localeValues, program);
}
validateConfigData(configData: any, configPath: string, file: BscFile, localeValues: string[], program: Program) {
if (!configData) {
return
}
if (Array.isArray(configData)) {
configData.forEach(item => this.validateConfigData(item, configPath, file, localeValues, program))
return;
}
if (typeof configData === 'object') {
for (var key in configData) {
const value = configData[key];
if (typeof value === 'string') {
const isKeyTranslatable = translatableXmlAttributes.includes(key)
const isValueTranslated = localeValues.includes(value)
if (isKeyTranslatable && !isValueTranslated) {
file.addDiagnostics([{
file: file,
range: {
start: { line: 0, character: 0 },
end: { line: 0, character: 0 }
},
message: `The attribute "${key}" with value "${value}" should be localized, but not found in locale files. Config file: ${configPath}`,
severity: DiagnosticSeverity.Error,
code: 'LOCALE_MISSING_TRANSLATIONS',
}]);
}
continue;
}
this.validateConfigData(value, configPath, file, localeValues, program);
}
}
}
parseConfigFile(configFile: string) {
if (jsonExtensions.includes(path.extname(configFile))) {
const contents = fs.readFileSync(configFile, 'utf8');
return json5.parse(contents);
}
if (yamlExtensions.includes(path.extname(configFile))) {
const contents = fs.readFileSync(configFile, 'utf8');
return YAML.parse(contents);
}
}
}
export default () => {