未验证 提交 e30341ad 编写于 作者: S Shu Muto 提交者: GitHub

Support multi locales in one translation file (#4814)

`zh` is same as `zh-cn`, so maintain `zh` and change `zh-cn` to link to `zh`.

Also, added support for `i18n/locales_not_for_build_local` that keeps
locales not for build as local setting for developer. Because building
dashboard takes much time.
上级 b5c3e9f6
......@@ -4,6 +4,9 @@ src/app/frontend/environments/version.ts
# Temporary translation file:
i18n/messages.new.xlf
# Local setting for locales not to build
i18n/locale_not_for_build_local
# Local copies of dependencies that should stay on developers' local machines:
node_modules/
......@@ -28,4 +31,3 @@ cypress/videos
# npm debug log:
npm-debug.log
......@@ -34,7 +34,17 @@ function build::frontend {
${NG_BIN} build --aot --prod --outputPath=${TMP_DIR}/frontend/en
languages=($(find i18n/* -type d|cut -d"/" -f2))
ignores=()
if [[ -f "i18n/locale_not_for_build_local" ]]; then
# Add locales to ignore on local setting file.
ignores=($(cat i18n/locale_not_for_build_local))
fi
for language in "${languages[@]}"; do
if [[ " ${ignores[@]} " =~ " ${language} " ]]; then
say "Skip building locale: ${language}"
continue
fi
mkdir -p ${FRONTEND_DIR}/${language}
say "Building frontend for locale: ${language}"
......
......@@ -16,7 +16,10 @@
# Collect current localized files
languages=($(find i18n/* -type d|cut -d"/" -f2))
for language in "${languages[@]}"; do
mv i18n/${language}/messages.${language}.xlf i18n
if [ ! -L i18n/${language}/messages.${language}.xlf ]; then
echo "Move translation file messages.${language}.xlf to be merged by xliffmerge."
mv i18n/${language}/messages.${language}.xlf i18n
fi
done
# Merge generated messages file into localized files.
......@@ -24,5 +27,8 @@ xliffmerge
# Deliver merged localized files into each locale directories.
for language in "${languages[@]}"; do
mv i18n/messages.${language}.xlf i18n/${language}
if [ -e i18n/messages.${language}.xlf ]; then
echo "Move merged file i18n/messages.${language}.xlf to i18n/${language}"
mv i18n/messages.${language}.xlf i18n/${language}
fi
done
......@@ -2,17 +2,17 @@
Based on current browser locale the Dashboard can be displayed in one of the supported languages listed below. In case it does not work, make sure that your browser's locale is identified with correct language code. In more details, Dashboard determines requested language based on HTTP `Accept-Language` header from browser. We can check which language codes are requested by browser on `Network` tab in developer tool of browser.
| Language | Code |
|--------------------|------|
| English (default) | en |
| French | fr |
| Japanese | ja |
| Korean | ko |
| Simplified Chinese | zh |
| Chinese (PRC) | zh-cn|
| Chinese (Hong Kong)| zh-hk|
| Chinese (Singapore)| zh-sg|
| Chinese (Taiwan) | zh-tw|
| Language | Code | Remarks |
|---------------------|---------|------------|
| English (default) | en | - |
| French | fr | - |
| Japanese | ja | - |
| Korean | ko | - |
| Simplified Chinese | zh | - |
| Chinese (PRC) | zh-cn | Same as zh |
| Chinese (Hong Kong) | zh-hk | - |
| Chinese (Singapore) | zh-sg | - |
| Chinese (Taiwan) | zh-tw | - |
## Building localized dashboard
......@@ -43,13 +43,19 @@ Find new localizable texts in `i18n/[locale]/messages.[locale].xlf` file and tra
Since dashboard team can not review translation files in your language, so dashboard team transfers authority to review and approve for updating your translation file. At first, you need to organize translation team for your language that manages dashboard translation file.
1. Add your locale, e.g. `fr` or `ja`, into `"languages"` array of `"xfillmergeOptions"` in `package.json` file.
**Important: Locales should be written in lower case to be handled by Dashboard, e.g. `zh-tw`, not `zh-TW`**
2. Run `npm run fix:i18n`. Then translation file for your language, e.g. `i18n/messages.fr.xlf`, would be generated.
3. Create a new directory for generated file, e.g. `i18n/fr` and move generated file there.
1. Create your locale directory under `i18n` directory, e.g. `i18n/fr` or `i18n/ja`.
2. Add your locale, e.g. `fr` or `ja`, into `"languages"` array of `"xliffmergeOptions"` in `package.json` file. If you want to add only locale and use an existing translation file for it, i.e. add `zh-cn` but use existing `i18n/zh/messages.zh.xlf` file for it, skip this step and go step 5.
**Important: Locales should be written in lower case to be handled by Dashboard, e.g. `zh-cn`, not `zh-CN`**
3. Run `npm run fix:i18n`. Then translation file for your language, e.g. `i18n/fr/messages.fr.xlf`, would be generated in your locale directory.
If `i18n/[locale]/messages.[locale].xlf` is not normal file type, our script ignores `xliffmerge` for the locale.
4. Open your translation file and translate texts in `<target>` element into your language.
5. If you want to use an existing translation file for the locale, create symbolic link `messages.[locale].xlf` to the existing translation file like follow:
```
cd i18n/zh-cn
ln -s ../zh/messages.zh.xlf messages.zh-cn.xlf
```
After preparation of new translation file, configure `i18n/locale conf.json` file to build translated dashboard as follows:
After preparation of new translation file, configure `i18n/locale_conf.json` file to support translated dashboard as follows:
```
{"translations": [ "en", "fr", "ko", "zh" ]}
......@@ -61,6 +67,13 @@ To add Japanese translation file, add `"ja"` into `"translations"` array in alph
{"translations": [ "en", "fr", "ja", "ko", "zh" ]}
```
To save time for building localized version in your develop environment, you can set locales not to build by creating `i18n/locale_not_for_build_local` and adding into it like below:
```
fr
ko
```
Then you can build your localized dashboard with `npm run build`.
Before submit Pull Request, add `i18n/[locale]/OWNERS` file for your translation team like below:
......@@ -68,7 +81,7 @@ Before submit Pull Request, add `i18n/[locale]/OWNERS` file for your translation
```
approvers:
- [your github account]
- [or your group name in kubernetes org]
- [and more approvers' github account]
labels:
- language/[your locale]
......
此差异已折叠。
../zh/messages.zh.xlf
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册