2022-10-06 10:34:04 -05:00
|
|
|
const fs = require('fs/promises');
|
|
|
|
const pseudoizer = require('pseudoizer');
|
2023-06-06 02:29:04 -05:00
|
|
|
const prettier = require('prettier');
|
2022-10-06 10:34:04 -05:00
|
|
|
|
|
|
|
function pseudoizeJsonReplacer(key, value) {
|
|
|
|
if (typeof value === 'string') {
|
2022-11-23 04:32:20 -06:00
|
|
|
// 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("")
|
2022-10-06 10:34:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.readFile('./public/locales/en-US/grafana.json').then((enJson) => {
|
|
|
|
const enMessages = JSON.parse(enJson);
|
2023-06-06 02:29:04 -05:00
|
|
|
// Add newline to make prettier happy
|
|
|
|
const pseudoJson = prettier.format(JSON.stringify(enMessages, pseudoizeJsonReplacer, 2), {
|
|
|
|
parser: 'json',
|
|
|
|
});
|
2022-10-06 10:34:04 -05:00
|
|
|
|
|
|
|
return fs.writeFile('./public/locales/pseudo-LOCALE/grafana.json', pseudoJson);
|
|
|
|
});
|