Skip to content

Commit 2f66eec

Browse files
authored
fix localization of toolbox subcategories and groups for static package targets (#11293)
1 parent 26cf9d3 commit 2f66eec

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

pxtlib/package.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,18 +1070,7 @@ namespace pxt {
10701070
})
10711071
})))
10721072
.then(() => {
1073-
// Subcategories and groups are translated in their respective package, but are not really APIs so
1074-
// there's no way for the translation to be saved with a block. To work around this, we copy the
1075-
// translations to the editor translations.
1076-
const strings = U.getLocalizedStrings();
1077-
Object.keys(loc).forEach((l) => {
1078-
if (U.startsWith(l, "{id:subcategory}") || U.startsWith(l, "{id:group}")) {
1079-
if (!strings[l]) {
1080-
strings[l] = loc[l];
1081-
}
1082-
}
1083-
});
1084-
U.setLocalizedStrings(strings);
1073+
U.copySubcategoryStrings(loc);
10851074

10861075
return Promise.resolve(loc);
10871076
});

pxtlib/util.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ namespace ts.pxtc.Util {
593593
}, ms);
594594
});
595595

596-
return Promise.race([ promise, timeoutPromise ])
596+
return Promise.race([promise, timeoutPromise])
597597
.then(output => {
598598
// clear any dangling timeout
599599
if (res) {
@@ -1253,7 +1253,7 @@ namespace ts.pxtc.Util {
12531253
"eu": { englishName: "Basque", localizedName: "Euskara" },
12541254
"fa": { englishName: "Persian", localizedName: "فارسی" },
12551255
"fi": { englishName: "Finnish", localizedName: "Suomi" },
1256-
"fil": {englishName: "Filipino", localizedName: "Filipino"},
1256+
"fil": { englishName: "Filipino", localizedName: "Filipino" },
12571257
"fo": { englishName: "Faroese", localizedName: "føroyskt" },
12581258
"fr": { englishName: "French", localizedName: "Français" },
12591259
"fr-CA": { englishName: "French (Canada)", localizedName: "Français (Canada)" },
@@ -1279,7 +1279,7 @@ namespace ts.pxtc.Util {
12791279
"kmr": { englishName: "Kurmanji (Kurdish)", localizedName: "کورمانجی‎" },
12801280
"kn": { englishName: "Kannada", localizedName: "ಕನ್ನಡ" },
12811281
"ko": { englishName: "Korean", localizedName: "한국어" },
1282-
"lo": { englishName: "Lao", localizedName: "ພາສາລາວ"},
1282+
"lo": { englishName: "Lao", localizedName: "ພາສາລາວ" },
12831283
"lt": { englishName: "Lithuanian", localizedName: "Lietuvių" },
12841284
"lv": { englishName: "Latvian", localizedName: "Latviešu" },
12851285
"ml-IN": { englishName: "Malayalam", localizedName: "മലയാളം" },
@@ -1364,7 +1364,7 @@ namespace ts.pxtc.Util {
13641364
.then((translations) => {
13651365
if (translations) {
13661366
setUserLanguage(code);
1367-
pxt.analytics?.addDefaultProperties({lang: code}); //set the new language in analytics.
1367+
pxt.analytics?.addDefaultProperties({ lang: code }); //set the new language in analytics.
13681368
setLocalizedStrings(translations);
13691369
}
13701370

@@ -1373,8 +1373,10 @@ namespace ts.pxtc.Util {
13731373
targetId, baseUrl, code, liveUpdateStrings,
13741374
ts.pxtc.Util.TranslationsKind.Apis)
13751375
.then(trs => {
1376-
if (trs)
1376+
if (trs) {
13771377
ts.pxtc.apiLocalizationStrings = trs;
1378+
copySubcategoryStrings(trs);
1379+
}
13781380
});
13791381
});
13801382
}
@@ -1468,6 +1470,23 @@ namespace ts.pxtc.Util {
14681470
}
14691471
}
14701472

1473+
export function copySubcategoryStrings(apis: pxt.Map<string>) {
1474+
const t = getLocalizedStrings();
1475+
1476+
if (apis) {
1477+
// Subcategories and groups are translated in their respective package, but are not really APIs so
1478+
// there's no way for the translation to be saved with a block. To work around this, we copy the
1479+
// translations to the editor translations.
1480+
for (const key of Object.keys(apis)) {
1481+
if (U.startsWith(key, "{id:group}") || U.startsWith(key, "{id:subcategory}")) {
1482+
t[key] = apis[key];
1483+
}
1484+
}
1485+
1486+
setLocalizedStrings(t);
1487+
}
1488+
}
1489+
14711490
export let httpRequestCoreAsync: (options: HttpRequestOptions) => Promise<HttpResponse>;
14721491
export let sha256: (hashData: string) => string;
14731492
export let getRandomBuf: (buf: Uint8Array) => void;
@@ -1978,7 +1997,7 @@ namespace ts.pxtc.Util {
19781997
* Attempts to remove commonly leaked PII
19791998
* @param property The property which will be removed if it contains user data
19801999
* @returns The new value for the property
1981-
*
2000+
*
19822001
* Taken from https://github.com/microsoft/vscode/blob/main/src/vs/platform/telemetry/common/telemetryUtils.ts
19832002
*/
19842003
function removePropertiesWithPossibleUserInfo(property: string): string {

0 commit comments

Comments
 (0)