translationRunner: improve types

environments/review-translatio-ibj395/deployments/1317
Alex Gleason 2022-11-08 15:33:47 -06:00
rodzic 51fc34ddea
commit 8ff1dddc7e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 12 dodań i 5 usunięć

Wyświetl plik

@ -0,0 +1,2 @@
[
]

Wyświetl plik

@ -116,8 +116,8 @@ manageTranslations({
// used in translations which are not used in the default message. // used in translations which are not used in the default message.
/* eslint-disable no-console */ /* eslint-disable no-console */
function findVariablesinAST(tree: parser.MessageFormatElement[]) { function findVariablesinAST(tree: parser.MessageFormatElement[]): Set<string> {
const result = new Set(); const result = new Set<string>();
tree.forEach((element) => { tree.forEach((element) => {
switch (element.type) { switch (element.type) {
case parser.TYPE.argument: case parser.TYPE.argument:
@ -142,7 +142,7 @@ function findVariablesinAST(tree: parser.MessageFormatElement[]) {
return result; return result;
} }
function findVariables(string: string) { function findVariables(string: string): Set<string> {
return findVariablesinAST(parser.parse(string)); return findVariablesinAST(parser.parse(string));
} }
@ -161,14 +161,19 @@ const extractedMessages = extractedMessagesFiles.reduce((acc, messageFile) => {
return acc; return acc;
}, [] as ExtractedDescriptor[]); }, [] as ExtractedDescriptor[]);
const translations = languages.map((language: string) => { interface Translation {
language: string,
data: Record<string, string>,
}
const translations: Translation[] = languages.map((language: string) => {
return { return {
language: language, language: language,
data: JSON.parse(fs.readFileSync(path.join(translationsDirectory, language + '.json'), 'utf8')), data: JSON.parse(fs.readFileSync(path.join(translationsDirectory, language + '.json'), 'utf8')),
}; };
}); });
function difference<T>(a: Set<T>, b: Set<T>) { function difference<T>(a: Set<T>, b: Set<T>): Set<T> {
return new Set(Array.from(a).filter(x => !b.has(x))); return new Set(Array.from(a).filter(x => !b.has(x)));
} }