Skip to content

Commit

Permalink
Fix localisation of help docs for langs like 'fr' (#10310) (#10311)
Browse files Browse the repository at this point in the history
For French the code is 'fr' which just returns a single part.
We can just use whichever parts are returned for the paths.

Co-authored-by: Matt Hillsdon <[email protected]>
  • Loading branch information
riknoll and microbit-matt-hillsdon authored Dec 9, 2024
1 parent 0580f13 commit 1000eee
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions webapp/src/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2001,25 +2001,16 @@ function shouldEventHideFlyout(ev: Blockly.Events.Abstract) {
function resolveLocalizedMarkdown(url: string) {
const editorPackage = pkg.getEditorPkg(pkg.mainPkg);

const [initialLang, baseLang, initialLangLowerCase] = pxt.Util.normalizeLanguageCode(pxt.Util.userLanguage());

const splitPath = url.split("/");
const fileName = splitPath.pop();
const dirName = splitPath.join("/");

let pathsToTest: string[];

if (initialLang && baseLang && initialLangLowerCase) {
pathsToTest = [
`${dirName}/_locales/${initialLang}/${fileName}`,
`${dirName}/_locales/${initialLangLowerCase}/${fileName}`,
`${dirName}/_locales/${baseLang}/${fileName}`,
url
];
}
else {
pathsToTest = [url];
}
const [initialLang, baseLang, initialLangLowerCase] = pxt.Util.normalizeLanguageCode(pxt.Util.userLanguage());
const priorityOrder = [initialLang, initialLangLowerCase, baseLang].filter((lang) => typeof lang === "string")
const pathsToTest = [
...priorityOrder.map(lang =>`${dirName}/_locales/${lang}/${fileName}`),
url
]

for (const path of pathsToTest) {
const file = editorPackage.lookupFile(path);
Expand Down

0 comments on commit 1000eee

Please sign in to comment.