From 8ff1dddc7e3a53171454ee8ff51c786f717e1766 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 8 Nov 2022 15:33:47 -0600 Subject: [PATCH] translationRunner: improve types --- app/soapbox/locales/whitelist_is.json | 2 ++ translationRunner.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 app/soapbox/locales/whitelist_is.json diff --git a/app/soapbox/locales/whitelist_is.json b/app/soapbox/locales/whitelist_is.json new file mode 100644 index 000000000..0d4f101c7 --- /dev/null +++ b/app/soapbox/locales/whitelist_is.json @@ -0,0 +1,2 @@ +[ +] diff --git a/translationRunner.ts b/translationRunner.ts index ad88f3db3..c4994648b 100644 --- a/translationRunner.ts +++ b/translationRunner.ts @@ -116,8 +116,8 @@ manageTranslations({ // used in translations which are not used in the default message. /* eslint-disable no-console */ -function findVariablesinAST(tree: parser.MessageFormatElement[]) { - const result = new Set(); +function findVariablesinAST(tree: parser.MessageFormatElement[]): Set { + const result = new Set(); tree.forEach((element) => { switch (element.type) { case parser.TYPE.argument: @@ -142,7 +142,7 @@ function findVariablesinAST(tree: parser.MessageFormatElement[]) { return result; } -function findVariables(string: string) { +function findVariables(string: string): Set { return findVariablesinAST(parser.parse(string)); } @@ -161,14 +161,19 @@ const extractedMessages = extractedMessagesFiles.reduce((acc, messageFile) => { return acc; }, [] as ExtractedDescriptor[]); -const translations = languages.map((language: string) => { +interface Translation { + language: string, + data: Record, +} + +const translations: Translation[] = languages.map((language: string) => { return { language: language, data: JSON.parse(fs.readFileSync(path.join(translationsDirectory, language + '.json'), 'utf8')), }; }); -function difference(a: Set, b: Set) { +function difference(a: Set, b: Set): Set { return new Set(Array.from(a).filter(x => !b.has(x))); }