mirror of https://github.com/grafana/grafana
Chore: Remove pseudoizer and use i18next-pseudo instead (#101690)
* Remove pseudoizer and use i18next-pseudo instead * Remove pseudo.mjs script * Conditionally add pseudo post processing to i18n config * Remove pseudo-locale in favour of post processing * Add wrapped property to pseudo stringspull/101573/head
parent
fd6a4908f1
commit
852243c8f0
File diff suppressed because it is too large
Load Diff
@ -1,63 +0,0 @@ |
||||
// @ts-check
|
||||
import { readFile, writeFile } from 'fs/promises'; |
||||
import { format } from 'prettier'; |
||||
import { pseudoize } from 'pseudoizer'; |
||||
import { hideBin } from 'yargs/helpers'; |
||||
import yargs from 'yargs/yargs'; |
||||
|
||||
const argv = await yargs(hideBin(process.argv)) |
||||
.option('mode', { |
||||
demandOption: true, |
||||
describe: 'Path to a template to use for each issue. See source bettererIssueTemplate.md for an example', |
||||
type: 'string', |
||||
choices: ['oss', 'enterprise', 'both'], |
||||
}) |
||||
.version(false).argv; |
||||
|
||||
const extractOSS = ['oss', 'both'].includes(argv.mode); |
||||
const extractEnterprise = ['enterprise', 'both'].includes(argv.mode); |
||||
|
||||
/** |
||||
* @param {string} key |
||||
* @param {unknown} value |
||||
*/ |
||||
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 : pseudoize(str))); |
||||
return translatedParts.join(''); |
||||
} |
||||
|
||||
return value; |
||||
} |
||||
/** |
||||
* @param {string} inputPath |
||||
* @param {string} outputPath |
||||
*/ |
||||
async function pseudoizeJson(inputPath, outputPath) { |
||||
const baseJson = await readFile(inputPath, 'utf-8'); |
||||
const enMessages = JSON.parse(baseJson); |
||||
const pseudoJson = JSON.stringify(enMessages, pseudoizeJsonReplacer, 2); |
||||
const prettyPseudoJson = await format(pseudoJson, { |
||||
parser: 'json', |
||||
}); |
||||
|
||||
await writeFile(outputPath, prettyPseudoJson); |
||||
console.log('Wrote', outputPath); |
||||
} |
||||
|
||||
//
|
||||
// OSS translations
|
||||
if (extractOSS) { |
||||
await pseudoizeJson('./public/locales/en-US/grafana.json', './public/locales/pseudo-LOCALE/grafana.json'); |
||||
} |
||||
|
||||
//
|
||||
// Enterprise translations
|
||||
if (extractEnterprise) { |
||||
await pseudoizeJson( |
||||
'./public/app/extensions/locales/en-US/grafana-enterprise.json', |
||||
'./public/app/extensions/locales/pseudo-LOCALE/grafana-enterprise.json' |
||||
); |
||||
} |
Loading…
Reference in new issue