From 9cec4c2e98c08c9220d7c4636163c7a0d86edf62 Mon Sep 17 00:00:00 2001 From: Levi Kipke Date: Tue, 24 Nov 2020 11:25:27 -0800 Subject: [PATCH] fix(stdlib): wait for async translations (#587) --- src/index.ts | 2 +- src/stdlib/Localization.ts | 31 ++++++++++++++++--------------- 2 files changed, 17 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); + parseTranslations(xmlNode, locale); + } catch (err) { + interpreter.stderr.write(`Error reading translations file ${filePath}: ${err}`); + } } - - parseTranslations(xmlNode, locale); - } - }); + }) + ); } export const Tr = new Callable("Tr", {