grafana/public/locales/pseudo.js
Ashley Harrison 2650aa5600
Internationalization: Correctly generate plural forms (#71341)
* user essentials mob! 🔱

lastFile:public/locales/pseudo-LOCALE/grafana.json

* user essentials mob! 🔱

* user essentials mob! 🔱

lastFile:contribute/internationalization.md

* user essentials mob! 🔱

lastFile:contribute/internationalization.md

* move pseudo generation to precommit hook if en-US file is modified

Co-authored-by: L-M-K-B <48948963+L-M-K-B@users.noreply.github.com>
Co-authored-by: tskarhed <1438972+tskarhed@users.noreply.github.com>

* fix unit tests

---------

Co-authored-by: Joao Silva <joao.silva@grafana.com>
Co-authored-by: joshhunt <josh@trtr.co>
Co-authored-by: Roxana Turc <anamaria-roxana.turc@grafana.com>
Co-authored-by: eledobleefe <laura.fernandez@grafana.com>
Co-authored-by: L-M-K-B <48948963+L-M-K-B@users.noreply.github.com>
Co-authored-by: tskarhed <1438972+tskarhed@users.noreply.github.com>
2023-07-11 16:37:01 +01:00

25 lines
856 B
JavaScript

const fs = require('fs/promises');
const pseudoizer = require('pseudoizer');
const prettier = require('prettier');
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);
// Add newline to make prettier happy
const pseudoJson = prettier.format(JSON.stringify(enMessages, pseudoizeJsonReplacer, 2), {
parser: 'json',
});
return fs.writeFile('./public/locales/pseudo-LOCALE/grafana.json', pseudoJson);
});