Skip to content

Commit

Permalink
doc: add readme for i18n-tool
Browse files Browse the repository at this point in the history
Signed-off-by: warjiang <1096409085@qq.com>
  • Loading branch information
warjiang committed Oct 9, 2024
1 parent 97675fe commit 3fd89e9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
43 changes: 43 additions & 0 deletions ui/packages/i18n-tool/README.md
Original file line number Diff line number Diff line change
@@ -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.


2 changes: 1 addition & 1 deletion ui/packages/i18n-tool/src/scan/glossary.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ function initGlossaries(glossaryFilePath) {

module.exports = {
initGlossaries
}
}
33 changes: 0 additions & 33 deletions ui/packages/i18n-tool/src/scan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
}

Expand Down

0 comments on commit 3fd89e9

Please sign in to comment.