From a7a96cbbbc1d60f5878b965ba4090caebf8d0fe8 Mon Sep 17 00:00:00 2001 From: Levi Kipke Date: Tue, 24 Nov 2020 10:32:02 -0800 Subject: [PATCH 1/2] fix(stdlib): wait for async translations --- src/index.ts | 2 +- src/stdlib/Localization.ts | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/index.ts b/src/index.ts index 44077f7a8..f4b545569 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,7 +70,7 @@ export async function execute(filenames: string[], options: Partial { - const filePath = path.join(rootDir, "locale", locale, "translations.ts"); - if (fs.existsSync(filePath)) { - let xmlNode: XmlDocument; - try { - let contents = await readFile(filePath, "utf-8"); - let xmlStr = contents.toString().replace(/\r?\n|\r/g, ""); - xmlNode = new XmlDocument(xmlStr); - } catch (err) { - interpreter.stderr.write(`Error reading translations file ${filePath}: ${err}`); - return; - } + await pSettle( + Array.from(locales).map(async (locale) => { + const filePath = path.join(rootDir, "locale", locale, "translations.ts"); + if (fs.existsSync(filePath)) { + let xmlNode: XmlDocument; + try { + let contents = await readFile(filePath, "utf-8"); + let xmlStr = contents.toString().replace(/\r?\n|\r/g, ""); + xmlNode = new XmlDocument(xmlStr); + } catch (err) { + interpreter.stderr.write(`Error reading translations file ${filePath}: ${err}`); + return; + } - parseTranslations(xmlNode, locale); - } - }); + parseTranslations(xmlNode, locale); + } + }) + ); } export const Tr = new Callable("Tr", { From 90a83cca5e72075039be58304de4ae3fe089e0d0 Mon Sep 17 00:00:00 2001 From: Levi Kipke Date: Tue, 24 Nov 2020 11:22:59 -0800 Subject: [PATCH 2/2] pr feedback --- src/stdlib/Localization.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/stdlib/Localization.ts b/src/stdlib/Localization.ts index d7b46c75d..e6ffff941 100644 --- a/src/stdlib/Localization.ts +++ b/src/stdlib/Localization.ts @@ -61,12 +61,10 @@ export async function loadTranslationFiles(interpreter: Interpreter, rootDir: st let contents = await readFile(filePath, "utf-8"); let xmlStr = contents.toString().replace(/\r?\n|\r/g, ""); xmlNode = new XmlDocument(xmlStr); + parseTranslations(xmlNode, locale); } catch (err) { interpreter.stderr.write(`Error reading translations file ${filePath}: ${err}`); - return; } - - parseTranslations(xmlNode, locale); } }) );