From 3fd89e9f8e60a66eee56bd69e1349e5b41e722af Mon Sep 17 00:00:00 2001 From: warjiang <1096409085@qq.com> Date: Wed, 9 Oct 2024 21:26:57 +0800 Subject: [PATCH] doc: add readme for i18n-tool Signed-off-by: warjiang <1096409085@qq.com> --- ui/packages/i18n-tool/README.md | 43 ++++++++++++++++++++++ ui/packages/i18n-tool/src/scan/glossary.js | 2 +- ui/packages/i18n-tool/src/scan/index.js | 33 ----------------- 3 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 ui/packages/i18n-tool/README.md diff --git a/ui/packages/i18n-tool/README.md b/ui/packages/i18n-tool/README.md new file mode 100644 index 0000000..4a3c8c3 --- /dev/null +++ b/ui/packages/i18n-tool/README.md @@ -0,0 +1,43 @@ +# Install + + +```shell +npm install -g @karmada/i18n-tool +``` + + +# Basic Usage +For a whole frontend project which need to i18n, you can do as following: +```shell +# init config for under your project +# here you can modify the config according to the instructions +i18n-tool/node_modules/.bin/i18n-tool init + +# scan the Chinese and replace with i18n function invoke +# generate corresponding locales files +i18n-tool/node_modules/.bin/i18n-tool scan -c ./i18n.config.cjs +``` + +For a directory which need to i18n, you can specify with `-d` options +```shell +i18n-tool/node_modules/.bin/i18n-tool scan -d directory/to/your/code +``` + +For a single file which need to i18n, you can specify with `-f` options +```shell +i18n-tool/node_modules/.bin/i18n-tool scan -f path/to/your/code/file +``` + +# Advanced Usage +For those advanced developer, maybe they need to specify glossaries install of automatic translation. For these kind of +scenarios, you can create a `glossaries.csv` under the directory of locales, the format of `glossaries.csv` should like +```csv +i18n-key,zh-CN,en-US +86385379cf9cfbc2c554944f1c054a45,概览,Overview +21a4e07b08a4efbbfe2b9d88c208836a,多云资源管理,MultiCloud Resource Management +85fe5099f6807dada65d274810933389,集群,Cluster +``` +after create the `glossaries.csv`, for the same i18n-key, `i18n-tool` will use the content specified in `glossaries.csv` +instead of automatic translation. + + \ No newline at end of file diff --git a/ui/packages/i18n-tool/src/scan/glossary.js b/ui/packages/i18n-tool/src/scan/glossary.js index ffb1d2f..0ee9781 100644 --- a/ui/packages/i18n-tool/src/scan/glossary.js +++ b/ui/packages/i18n-tool/src/scan/glossary.js @@ -26,4 +26,4 @@ function initGlossaries(glossaryFilePath) { module.exports = { initGlossaries -} \ No newline at end of file +} diff --git a/ui/packages/i18n-tool/src/scan/index.js b/ui/packages/i18n-tool/src/scan/index.js index 87103e1..1ec5772 100644 --- a/ui/packages/i18n-tool/src/scan/index.js +++ b/ui/packages/i18n-tool/src/scan/index.js @@ -101,40 +101,7 @@ async function scan(cmdOptions) { } } debug('groupedGlossaryData is %O', groupedGlossaryData); - /* - const updatedDataWithoutGlossaryByLang = options.targetLangs - .map(targetLang => { - const updatedDataWithoutGlossary = Object.keys(updatedData) - .reduce((p, c) => { - const key = c - if (key in glossaryData && glossaryData[key][targetLang]) { - return p - } - p[key] = updatedData[key] - return p - }, {}) - return { - lang: targetLang, - updatedDataWithoutGlossary - } - }) - .reduce((p, c) => { - const {lang, updatedDataWithoutGlossary} = c; - return { - ...p, - [lang]: updatedDataWithoutGlossary - } - }, {}) - - debug('updatedDataWithoutGlossaryByLang is %O', updatedDataWithoutGlossaryByLang) - debug('updatedData is %O', updatedData) - */ if (needUpdateLocale) { - // const tmpData = groupedGlossaryData['zh-CN'] || updatedData - // fs.writeFileSync(cnLocalePath, JSON.stringify({ - // ...existingData, - // ...tmpData, - // })) updateLocale(cnLocalePath, updatedData, groupedGlossaryData['zh-CN']) }