feat(i18n, client): migrate meta translations (#40885)

This commit is contained in:
Nicholas Carrigan (he/him)
2021-02-03 00:03:52 -08:00
committed by GitHub
parent f5f2df187b
commit 1a642ba542
16 changed files with 159 additions and 123 deletions

View File

@@ -5,6 +5,7 @@ const { availableLangs } = require('./allLangs');
const { trendingSchema } = require('./trending-schema');
const { motivationSchema } = require('./motivation-schema');
const { introSchema } = require('./intro-schema');
const { metaTagsSchema } = require('./meta-tags-schema');
/**
* Flattens a nested object structure into a single
@@ -105,6 +106,7 @@ const translationSchemaKeys = Object.keys(flattenAnObject(translationsSchema));
const trendingSchemaKeys = Object.keys(flattenAnObject(trendingSchema));
const motivationSchemaKeys = Object.keys(flattenAnObject(motivationSchema));
const introSchemaKeys = Object.keys(flattenAnObject(introSchema));
const metaTagsSchemaKeys = Object.keys(flattenAnObject(metaTagsSchema));
/**
* Function that checks the translations.json file
@@ -236,7 +238,35 @@ const introSchemaValidation = languages => {
});
};
const metaTagsSchemaValidation = languages => {
languages.forEach(language => {
const filePath = path.join(
__dirname,
`/locales/${language}/meta-tags.json`
);
const fileData = fs.readFileSync(filePath);
const fileJson = JSON.parse(fileData);
const fileKeys = Object.keys(flattenAnObject(fileJson));
findMissingKeys(fileKeys, metaTagsSchemaKeys, `${language}/meta-tags.json`);
findExtraneousKeys(
fileKeys,
metaTagsSchemaKeys,
`${language}/metaTags.json`
);
const emptyKeys = noEmptyObjectValues(fileJson);
if (emptyKeys.length) {
throw new Error(
`${language}/metaTags.json has these empty keys: ${emptyKeys.join(
', '
)}`
);
}
console.info(`${language} metaTags.json is correct!`);
});
};
translationSchemaValidation(availableLangs.client);
trendingSchemaValidation(availableLangs.client);
motivationSchemaValidation(availableLangs.client);
introSchemaValidation(availableLangs.client);
metaTagsSchemaValidation(availableLangs.client);