[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 ### Fixed
- Show videos watch progress in playlist view - Show videos watch progress in playlist view
- Missing localization in certain views
## [0.39.1] - 2025-05-23 ## [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 ### 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 ## [0.17.3] - 2023-12-13
@@ -22,7 +22,7 @@
showDivider="false"> showDivider="false">
<Label <Label
id="scanLabel" id="scanLabel"
text="Scan the QR Code" text="Scan the QR code"
horizAlign="center" horizAlign="center"
wrap="true" width="400"> wrap="true" width="400">
<Font role="font" uri="font:SystemFontFile" size="24" /> <Font role="font" uri="font:SystemFontFile" size="24" />
@@ -19,8 +19,9 @@ function Init()
m.top.observeFieldScoped("buttonSelected", FuncName(Close)) m.top.observeFieldScoped("buttonSelected", FuncName(Close))
m.top.observeFieldScoped("wasClosed", FuncName(OnWasClosed)) m.top.observeFieldScoped("wasClosed", FuncName(OnWasClosed))
scanLabel = m.top.findNode("scanLabel") scanLabel = m.top.findNode("scanLabel")
' TODO:P2 localize all dialog items
scanLabel.text = Tr(Locale.Dialogs.ScanTheQrCode) 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 end function
function OnNodeReady() function OnNodeReady()
@@ -10,7 +10,8 @@
<StdDlgTitleArea primaryTitle="Login to YouTube" /> <StdDlgTitleArea primaryTitle="Login to YouTube" />
<StdDlgContentArea> <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..." /> <StdDlgTextItem id="codeLabel" text="Loading..." />
</StdDlgContentArea> </StdDlgContentArea>
<StdDlgButtonArea id="buttonArea"> <StdDlgButtonArea id="buttonArea">
@@ -24,7 +25,7 @@
showDivider="false"> showDivider="false">
<Label <Label
id="scanLabel" id="scanLabel"
text="Scan the QR Code" text="Scan the QR code"
horizAlign="center" horizAlign="center"
wrap="true" width="400"> wrap="true" width="400">
<Font role="font" uri="font:SystemFontFile" size="24" /> <Font role="font" uri="font:SystemFontFile" size="24" />
@@ -37,11 +38,11 @@
loadHeight="300" loadHeight="300"
padding="10" padding="10"
translation="[50, 50]" /> translation="[50, 50]" />
<Label <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="https://yt.be/activate"
horizAlign="center" horizAlign="center"
width="400" width="400"
translation="[0, 380]" translation="[0, 380]">
text="https://yt.be/activate">
<Font role="font" uri="font:MediumSystemFontFile" size="18" /> <Font role="font" uri="font:MediumSystemFontFile" size="18" />
</Label> </Label>
</StdDlgSideCardArea> </StdDlgSideCardArea>
+1 -2
View File
@@ -42,8 +42,7 @@
<AppVersionLabel <AppVersionLabel
fontUri="font:BoldSystemFontFile" fontUri="font:BoldSystemFontFile"
fontSize="16" fontSize="16"
translation="[0, 48]" translation="[0, 48]" />
/>
</Poster> </Poster>
<MarkupList <MarkupList
@@ -43,8 +43,7 @@
showRowLabel="[true]" showRowLabel="[true]"
rowFocusAnimationStyle="floatingfocus" rowFocusAnimationStyle="floatingfocus"
variableWidthItems="true" variableWidthItems="true"
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png" focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png" />
/>
</Group> </Group>
</children> </children>
</component> </component>
@@ -36,7 +36,9 @@
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png"> focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png">
<ContentNode role="content"> <ContentNode role="content">
<ContentNode> <ContentNode>
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<BackendTypeContentNode id="BackendTypeYouTube" title="YouTube" backendLogoUri="pkg:/images/youtube-logo.png" /> <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" /> <BackendTypeContentNode id="BackendTypeInvidious" title="Invidious" backendLogoUri="pkg:/images/invidious-logo.png" />
</ContentNode> </ContentNode>
</ContentNode> </ContentNode>
@@ -65,8 +65,7 @@
id="backendTypePoster" id="backendTypePoster"
width="60" width="60"
height="60" height="60"
translation="[110,110]" translation="[110,110]" />
/>
</CirclePoster> </CirclePoster>
<Poster <Poster
id="CrownPoster" id="CrownPoster"
@@ -81,13 +81,12 @@ function LoginWithInvidious() as void
end function end function
function ShowLoginWithYouTubeDialog() as void function ShowLoginWithYouTubeDialog() as void
' TODO:P2 localize
dialog = DialogUtils.ShowDialogEx({ dialog = DialogUtils.ShowDialogEx({
title: "Disclaimer" title: Tr(Locale.Dialogs.Disclaimer)
message: [ 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." Tr(Locale.Dialogs.YouTubeLoginDisclaimer1)
"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." Tr(Locale.Dialogs.YouTubeLoginDisclaimer2)
"Use responsibly, especially if your YouTube account is tied to business or monetization." Tr(Locale.Dialogs.YouTubeLoginDisclaimer3)
] ]
large: true large: true
buttons: [ buttons: [
@@ -52,8 +52,7 @@
id="backendTypePoster" id="backendTypePoster"
width="60" width="60"
height="60" height="60"
translation="[110,110]" translation="[110,110]" />
/>
</CirclePoster> </CirclePoster>
<Poster <Poster
id="CrownPoster" id="CrownPoster"
@@ -16,8 +16,7 @@
vertAlign="center" vertAlign="center"
text="Could not get IP address: are we connected to the internet?" text="Could not get IP address: are we connected to the internet?"
wrap="true" wrap="true"
translation="[145,0]" translation="[145,0]" />
/>
</Group> </Group>
<Group id="yesInternet" visible="false"> <Group id="yesInternet" visible="false">
<LayoutGroup <LayoutGroup
@@ -83,9 +82,9 @@
vertAlignment="center" vertAlignment="center"
translation="[0,245]"> translation="[0,245]">
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]"> <LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
font="font:SmallSystemFont" <Label text="1."
text="1." /> font="font:SmallSystemFont" />
<Label <Label
font="font:SmallSystemFont" font="font:SmallSystemFont"
width="380" width="380"
@@ -93,9 +92,9 @@
text="On your phone, connect to the same Wi-Fi network as this device." /> text="On your phone, connect to the same Wi-Fi network as this device." />
</LayoutGroup> </LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]"> <LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
font="font:SmallSystemFont" <Label text="2."
text="2." /> font="font:SmallSystemFont" />
<Label <Label
font="font:SmallSystemFont" font="font:SmallSystemFont"
width="380" width="380"
@@ -103,14 +102,14 @@
text="Open the YouTube app on your phone." /> text="Open the YouTube app on your phone." />
</LayoutGroup> </LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]"> <LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
font="font:SmallSystemFont" <Label text="3."
text="3." /> font="font:SmallSystemFont" />
<MultiStyleLabel <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<MultiStyleLabel text="Tap the cast icon and select this device."
id="WifiInstructionWithDeviceNameLabel" id="WifiInstructionWithDeviceNameLabel"
width="380" width="380"
wrap="true" wrap="true" />
text="Tap the cast icon and select this device." />
</LayoutGroup> </LayoutGroup>
<Label <Label
text="Roku connected to:" text="Roku connected to:"
@@ -131,9 +130,9 @@
vertAlignment="center" vertAlignment="center"
translation="[0,245]"> translation="[0,245]">
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]"> <LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
font="font:SmallSystemFont" <Label text="1."
text="1." /> font="font:SmallSystemFont" />
<Label <Label
font="font:SmallSystemFont" font="font:SmallSystemFont"
width="380" width="380"
@@ -141,9 +140,9 @@
text="On your phone, open the YouTube app." /> text="On your phone, open the YouTube app." />
</LayoutGroup> </LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]"> <LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
font="font:SmallSystemFont" <Label text="2."
text="2." /> font="font:SmallSystemFont" />
<Label <Label
font="font:SmallSystemFont" font="font:SmallSystemFont"
width="380" width="380"
@@ -151,9 +150,9 @@
text="Tap the cast icon." /> text="Tap the cast icon." />
</LayoutGroup> </LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="[15]"> <LayoutGroup layoutDirection="horiz" itemSpacings="[15]">
<Label <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
font="font:SmallSystemFont" <Label text="3."
text="3." /> font="font:SmallSystemFont" />
<Label <Label
font="font:SmallSystemFont" font="font:SmallSystemFont"
width="380" width="380"
@@ -18,16 +18,14 @@
<DynamicMiniKeyboard <DynamicMiniKeyboard
id="keyboard" id="keyboard"
translation="[695,110]" translation="[695,110]" />
/>
<ButtonGroup <ButtonGroup
id="suggestions" id="suggestions"
focusable="false" focusable="false"
minWidth="400" minWidth="400"
maxWidth="480" maxWidth="480"
buttonHeight="50" buttonHeight="50"
translation="[125,100]" translation="[125,100]" />
/>
<VideoRowList <VideoRowList
itemComponentName="RowCell" itemComponentName="RowCell"
id="rowList" id="rowList"
@@ -43,8 +41,7 @@
showRowLabel="[true]" showRowLabel="[true]"
rowFocusAnimationStyle="floatingfocus" rowFocusAnimationStyle="floatingfocus"
variableWidthItems="true" variableWidthItems="true"
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png" focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png" />
/>
<Animation <Animation
id="scrollAnimation" id="scrollAnimation"
duration="0.3"> duration="0.3">
@@ -10,7 +10,7 @@
translation="[380,96]" /> translation="[380,96]" />
<Label <Label
id="failedLabel" id="failedLabel"
text="Failed to load Invidious public instances." text="Failed to load Invidious public instances"
horizAlign="center" horizAlign="center"
translation="[0,60]" translation="[0,60]"
width="960" /> width="960" />
@@ -16,29 +16,29 @@
<Font role="font" uri="font:SystemFontFile" size="18" /> <Font role="font" uri="font:SystemFontFile" size="18" />
</Label> </Label>
<LayoutGroup layoutDirection="horiz"> <LayoutGroup layoutDirection="horiz">
<Button <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Button text="-"
id="MinusButton" id="MinusButton"
iconUri="" iconUri=""
focusedIconUri="" focusedIconUri=""
minWidth="64" minWidth="64"
maxWidth="64" maxWidth="64"
showFocusFootprint="true" showFocusFootprint="true" />
text="-" /> <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Button <Button text="0"
id="NumberButton" id="NumberButton"
iconUri="" iconUri=""
focusedIconUri="" focusedIconUri=""
minWidth="150" minWidth="150"
showFocusFootprint="true" showFocusFootprint="true" />
text="0" /> <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Button <Button text="+"
id="PlusButton" id="PlusButton"
iconUri="" iconUri=""
focusedIconUri="" focusedIconUri=""
minWidth="64" minWidth="64"
maxWidth="64" maxWidth="64"
showFocusFootprint="true" showFocusFootprint="true" />
text="+" />
</LayoutGroup> </LayoutGroup>
</children> </children>
</component> </component>
@@ -23,11 +23,17 @@
<ContentNode role="content"> <ContentNode role="content">
<ContentNode id="auto" title="Auto" /> <ContentNode id="auto" title="Auto" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="1080p" title="1080p" /> <ContentNode id="1080p" title="1080p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="720p" title="720p" /> <ContentNode id="720p" title="720p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="480p" title="480p" /> <ContentNode id="480p" title="480p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="360p" title="360p" /> <ContentNode id="360p" title="360p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="240p" title="240p" /> <ContentNode id="240p" title="240p" />
<!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<ContentNode id="144p" title="144p" /> <ContentNode id="144p" title="144p" />
</ContentNode> </ContentNode>
</CheckList> </CheckList>
@@ -16,9 +16,9 @@
height="50" height="50"
translation="[10,10]"> translation="[10,10]">
</Poster> </Poster>
<Label <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
<Label text="..."
id="categoryLabel" id="categoryLabel"
text="..."
font="font:SmallestBoldSystemFont" font="font:SmallestBoldSystemFont"
lineSpacing="5" lineSpacing="5"
horizAlign="center" horizAlign="center"
@@ -20,8 +20,8 @@
<function name="PlayWithContent" /> <function name="PlayWithContent" />
</interface> </interface>
<children> <children>
<SimpleLabel <!-- bs:disable-next-line LOCALE_MISSING_TRANSLATIONS -->
text="Dev Player!" <SimpleLabel text="Dev Player!"
color="#FF0000" color="#FF0000"
fontUri="font:SmallestBoldSystemFont" fontUri="font:SmallestBoldSystemFont"
horizOrigin="right" horizOrigin="right"
@@ -264,6 +264,34 @@
<source>Failed to get session data. Please restart Playlet to use the cast function.</source> <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> <translation>Failed to get session data. Please restart Playlet to use the cast function.</translation>
</message> </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> <message>
<source>Invidious custom instance</source> <source>Invidious custom instance</source>
<translation>Invidious custom instance</translation> <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." LoungeFailedToGetLoungeToken = "Failed to get lounge token. Please restart Playlet to use the cast function."
LoungeInvalidResponse = "Invalid response: %1" LoungeInvalidResponse = "Invalid response: %1"
LoungeFailedToGetSessionData = "Failed to get session data. Please restart Playlet to use the cast function." 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 end enum
@locale @locale
+117 -21
View File
@@ -5,6 +5,7 @@
// 4. Xml components do not have values that can be translated by accident // 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 // - 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 // - 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 { import {
BrsFile, BrsFile,
@@ -19,13 +20,18 @@ import {
isBrsFile, isBrsFile,
isXmlFile isXmlFile
} from "brighterscript"; } from "brighterscript";
import { existsSync, readFileSync } from "fs"; import fs from "fs";
import { join as pathJoin } from "path"; import path from "path";
import * as xml2js from 'xml2js'; import * as xml2js from 'xml2js';
import { globSync } from 'glob'; import { globSync } from 'glob';
import { SGNode } from "brighterscript/dist/parser/SGTypes"; 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 { export class LocaleValidationPlugin implements CompilerPlugin {
public name = 'LocaleValidationPlugin'; public name = 'LocaleValidationPlugin';
@@ -44,6 +50,18 @@ export class LocaleValidationPlugin implements CompilerPlugin {
} }
afterFileValidate(file: BscFile) { 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)) { if (!isXmlFile(file)) {
return; return;
} }
@@ -64,7 +82,7 @@ export class LocaleValidationPlugin implements CompilerPlugin {
const value = field.value; const value = field.value;
if (value && localeValues.includes(value)) { if (value && localeValues.includes(value)) {
const id = field.id; const id = field.id;
if (!allowedXmlAttributes.includes(id)) { if (!translatableXmlAttributes.includes(id)) {
file.addDiagnostics([{ file.addDiagnostics([{
file: file, file: file,
range: field.range!, range: field.range!,
@@ -87,17 +105,32 @@ export class LocaleValidationPlugin implements CompilerPlugin {
validateSgNode(node: SGNode, localeValues: string[], file: XmlFile) { validateSgNode(node: SGNode, localeValues: string[], file: XmlFile) {
node.attributes.forEach((attribute) => { node.attributes.forEach((attribute) => {
const value = attribute.value.text; const value = attribute.value.text;
if (value && localeValues.includes(value)) { if (!value) {
const key = attribute.key.text; return;
if (!allowedXmlAttributes.includes(key)) { }
file.addDiagnostics([{
file: file, const key = attribute.key.text;
range: attribute.value.range!, const isKeyTranslatable = translatableXmlAttributes.includes(key)
message: `Locale value found in xml component: "${value}" but the attribute "${key}" is not allowed to be localized.`, const isValueTranslated = localeValues.includes(value)
severity: DiagnosticSeverity.Error,
code: 'LOCALE_VALUE_IN_XML', 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 rootDir = program.options.rootDir!;
const translationFiles = globSync(`locale/**/translations.ts`, { cwd: rootDir }); const translationFiles = globSync(`locale/**/translations.ts`, { cwd: rootDir });
translationFiles.forEach((translationFile) => { translationFiles.forEach((translationFile) => {
const srcPath = pathJoin(rootDir, translationFile); const srcPath = path.join(rootDir, translationFile);
const pkgPath = pathJoin('pkg:/', translationFile); const pkgPath = path.join('pkg:/', translationFile);
const xmlFile = new XmlFile(srcPath, pkgPath, program); const xmlFile = new XmlFile(srcPath, pkgPath, program);
this.validateTranslations(xmlFile, program, this.localeValues, this.enums[0].file); 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) { validateEnglishTranslations(program: Program, localeValues: string[], file: BrsFile) {
const translationFile = 'locale/en_US/translations.ts'; const translationFile = 'locale/en_US/translations.ts';
const srcPath = pathJoin(program.options.rootDir!, translationFile); const srcPath = path.join(program.options.rootDir!, translationFile);
const pkgPath = pathJoin('pkg:/', translationFile); const pkgPath = path.join('pkg:/', translationFile);
const xmlFile = new XmlFile(srcPath, pkgPath, program); const xmlFile = new XmlFile(srcPath, pkgPath, program);
const englishTranslations = this.loadTranslationsFile(program, xmlFile); const englishTranslations = this.loadTranslationsFile(program, xmlFile);
@@ -216,10 +249,10 @@ export class LocaleValidationPlugin implements CompilerPlugin {
loadTranslationsFile(program: Program, translationFile: XmlFile) { loadTranslationsFile(program: Program, translationFile: XmlFile) {
// load xml ts translation file // load xml ts translation file
if (!existsSync(translationFile.srcPath)) { if (!fs.existsSync(translationFile.srcPath)) {
return null; return null;
} }
const content = readFileSync(translationFile.srcPath, 'utf8'); const content = fs.readFileSync(translationFile.srcPath, 'utf8');
const xml = this.parseXml(content); const xml = this.parseXml(content);
if (!xml || !xml.TS || !xml.TS.context || !xml.TS.context[0].message) { if (!xml || !xml.TS || !xml.TS.context || !xml.TS.context[0].message) {
return null; return null;
@@ -318,6 +351,69 @@ export class LocaleValidationPlugin implements CompilerPlugin {
} }
return false 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 () => { export default () => {