grafana/public/locales/psuedo.js
Josh Hunt c02f2321c1
I18n: Fix variables not interpolating with pseudo localisation (#59145)
* I18n: Don't pseudolocalise string variables

* clean up
2022-11-23 10:32:20 +00:00

21 lines
734 B
JavaScript

const fs = require('fs/promises');
const pseudoizer = require('pseudoizer');
function pseudoizeJsonReplacer(key, value) {
if (typeof value === 'string') {
// Split string on brace-enclosed segments. Odd indices will be {{variables}}
const phraseParts = value.split(/(\{\{[^}]+}\})/g);
const translatedParts = phraseParts.map((str, index) => index % 2 ? str : pseudoizer.pseudoize(str))
return translatedParts.join("")
}
return value;
}
fs.readFile('./public/locales/en-US/grafana.json').then((enJson) => {
const enMessages = JSON.parse(enJson);
const pseudoJson = JSON.stringify(enMessages, pseudoizeJsonReplacer, 2);
return fs.writeFile('./public/locales/pseudo-LOCALE/grafana.json', pseudoJson);
});