Upgrade i18n diff script and include a list of approved matches

This commit is contained in:
Ryon Coleman 2024-12-20 13:35:20 -05:00 committed by Carlos Felix
parent f4e0f63363
commit 390d19d9c6
2 changed files with 65 additions and 14 deletions

View file

@ -1,25 +1,42 @@
/**
* Validates translation coverage between en.json and es.json by checking:
* - Missing/unused translation keys
* - Identical text that may need translation (excluding approved matches)
*/
const enJson = require('./en.json');
const esJson = require('./es.json');
const {identicalKeysEnEs} = require('./identicalKeysEnEs');
const enKeys = Object.keys(enJson);
const esKeys = Object.keys(esJson);
const enKeysNotInEs = enKeys.filter((key) => !esKeys.includes(key));
const esKeysNotInEn = esKeys.filter((key) => !enKeys.includes(key));
const missingKeys = enKeys.filter((key) => !esKeys.includes(key));
const unusedKeys = esKeys.filter((key) => !enKeys.includes(key));
// Check for missing/outdated keys
if (enKeysNotInEs.length > 0 || esKeysNotInEn.length > 0) {
console.log('\nKeys to be added to es.json: ');
console.log(enKeysNotInEs);
console.log('\nKeys to be removed from es.json: ');
console.log(esKeysNotInEn);
if (missingKeys.length > 0 || unusedKeys.length > 0) {
console.log('\nMISSING: These keys need to be added to es.json:');
console.log(missingKeys);
console.log('\nUNUSED: These keys in es.json are not in en.json:');
console.log(unusedKeys);
} else {
console.log('All keys from en.json appear to exist in es.json');
console.log('SUCCESS: All keys match between en.json and es.json');
}
// Check for identical translations
const identicalValues = enKeys.filter((key) => enJson[key].defaultMessage === esJson[key]);
if (identicalValues.length > 0) {
console.log('\nKeys where es.json is the same as en.json: ');
console.log(identicalValues);
const untranslatedValues = enKeys.filter((key) =>
enJson[key].defaultMessage === esJson[key] && !identicalKeysEnEs.includes(key),
);
if (untranslatedValues.length > 0) {
console.log('\nIDENTICAL: These keys have identical text in both languages');
console.log('(If any of these are intentionally identical, add them to identicalKeysEnEs.js):');
console.log(untranslatedValues);
}
// Check for keys in identicalKeysEnEs that no longer exist in either translation file
const nonexistentIdenticalKeys = identicalKeysEnEs.filter(
(key) => !enKeys.includes(key) || !esKeys.includes(key),
);
if (nonexistentIdenticalKeys.length > 0) {
console.log('\nOUTDATED MATCH: These keys in identicalKeysEnEs.js no longer exist in translations:');
console.log(nonexistentIdenticalKeys);
}

View file

@ -0,0 +1,34 @@
/**
* Lists translation keys that are intentionally identical between English and Spanish translations.
* These keys represent content that should remain the same in both languages, such as:
* - URLs and external links
* - Standardized abbreviations
* - Words like "no" that are the same in both languages
*
* This file must be manually updated as needed.
*/
export const identicalKeysEnEs = [
'common.pages.footer.findcontact.link',
'common.pages.footer.whitehouselogoalt',
'common.pages.tsd.url',
'explore.map.page.map.layer.selector.tribal.short',
'explore.map.page.map.territoryFocus.alaska.long',
'explore.map.page.map.territoryFocus.alaska.short',
'explore.map.page.map.territoryFocus.american.samoa.short',
'explore.map.page.map.territoryFocus.commonwealth.nmp.short',
'explore.map.page.map.territoryFocus.guam.long',
'explore.map.page.map.territoryFocus.guam.short',
'explore.map.page.map.territoryFocus.hawaii.short',
'explore.map.page.map.territoryFocus.lower48.short',
'explore.map.page.map.territoryFocus.puerto_rico.long',
'explore.map.page.map.territoryFocus.puerto_rico.short',
'explore.map.page.map.territoryFocus.us.virgin.islands.short',
'explore.map.page.side.panel.exceed.burden.answer.no',
'explore.map.page.side.panel.indicator.diabetes',
'explore.map.page.side.panel.info.para.4',
'explore.map.page.side.panel.not.community.of.focus',
'methodology.page.dataset.indicator.diabetes.title.text',
];
export default identicalKeysEnEs;