mirror of https://github.com/grafana/grafana
I18n: Support for Enterprise translations (#86215)
* I18n: Support for Enterprise translations * don't attempt to link to enterprise in tests * move extract script to makefile to optionally support enterprise * update references to old extract script * update docs * thank god for unit testspull/86517/head^2
parent
272b2e139a
commit
fe24404432
@ -0,0 +1,8 @@ |
|||||||
|
const baseConfig = require('./i18next-parser.config.cjs'); |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
...baseConfig, |
||||||
|
defaultNamespace: 'grafana-enterprise', |
||||||
|
input: ['../../public/app/extensions/**/*.{tsx,ts}'], |
||||||
|
output: './public/app/extensions/locales/$LOCALE/$NAMESPACE.json', |
||||||
|
}; |
||||||
@ -1,24 +0,0 @@ |
|||||||
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(async (enJson) => { |
|
||||||
const enMessages = JSON.parse(enJson); |
|
||||||
// Add newline to make prettier happy
|
|
||||||
const pseudoJson = await prettier.format(JSON.stringify(enMessages, pseudoizeJsonReplacer, 2), { |
|
||||||
parser: 'json', |
|
||||||
}); |
|
||||||
|
|
||||||
return fs.writeFile('./public/locales/pseudo-LOCALE/grafana.json', pseudoJson); |
|
||||||
}); |
|
||||||
@ -0,0 +1,63 @@ |
|||||||
|
// @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