Skip to content

Commit f093ae8

Browse files
committed
Support multi locales in one translation file
`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.
1 parent 998f3aa commit f093ae8

File tree

5 files changed

+52
-5255
lines changed

5 files changed

+52
-5255
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ src/app/frontend/environments/version.ts
44
# Temporary translation file:
55
i18n/messages.new.xlf
66

7+
# Local setting for locales not to build
8+
i18n/locale_not_for_build_local
9+
710
# Local copies of dependencies that should stay on developers' local machines:
811
node_modules/
912

@@ -28,4 +31,3 @@ cypress/videos
2831

2932
# npm debug log:
3033
npm-debug.log
31-

aio/scripts/build.sh

+10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ function build::frontend {
3434
${NG_BIN} build --aot --prod --outputPath=${TMP_DIR}/frontend/en
3535

3636
languages=($(find i18n/* -type d|cut -d"/" -f2))
37+
ignores=()
38+
if [[ -f "i18n/locale_not_for_build_local" ]]; then
39+
# Add locales to ignore on local setting file.
40+
ignores=($(cat i18n/locale_not_for_build_local))
41+
fi
3742
for language in "${languages[@]}"; do
43+
if [[ " ${ignores[@]} " =~ " ${language} " ]]; then
44+
say "Skip building locale: ${language}"
45+
continue
46+
fi
47+
3848
mkdir -p ${FRONTEND_DIR}/${language}
3949

4050
say "Building frontend for locale: ${language}"

aio/scripts/xliffmerge.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
# Collect current localized files
1717
languages=($(find i18n/* -type d|cut -d"/" -f2))
1818
for language in "${languages[@]}"; do
19-
mv i18n/${language}/messages.${language}.xlf i18n
19+
if [ ! -L i18n/${language}/messages.${language}.xlf ]; then
20+
echo "Move translation file messages.${language}.xlf to be merged by xliffmerge."
21+
mv i18n/${language}/messages.${language}.xlf i18n
22+
fi
2023
done
2124

2225
# Merge generated messages file into localized files.
2326
xliffmerge
2427

2528
# Deliver merged localized files into each locale directories.
2629
for language in "${languages[@]}"; do
27-
mv i18n/messages.${language}.xlf i18n/${language}
30+
if [ -e i18n/messages.${language}.xlf ]; then
31+
echo "Move merged file i18n/messages.${language}.xlf to i18n/${language}"
32+
mv i18n/messages.${language}.xlf i18n/${language}
33+
fi
2834
done

docs/developer/internationalization.md

+30-17
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
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.
44

5-
| Language | Code |
6-
|--------------------|------|
7-
| English (default) | en |
8-
| French | fr |
9-
| Japanese | ja |
10-
| Korean | ko |
11-
| Simplified Chinese | zh |
12-
| Chinese (PRC) | zh-cn|
13-
| Chinese (Hong Kong)| zh-hk|
14-
| Chinese (Singapore)| zh-sg|
15-
| Chinese (Taiwan) | zh-tw|
5+
| Language | Code | Remarks |
6+
|---------------------|---------|------------|
7+
| English (default) | en | - |
8+
| French | fr | - |
9+
| Japanese | ja | - |
10+
| Korean | ko | - |
11+
| Simplified Chinese | zh | - |
12+
| Chinese (PRC) | zh-cn | Same as zh |
13+
| Chinese (Hong Kong) | zh-hk | - |
14+
| Chinese (Singapore) | zh-sg | - |
15+
| Chinese (Taiwan) | zh-tw | - |
1616

1717
## Building localized dashboard
1818

@@ -43,13 +43,19 @@ Find new localizable texts in `i18n/[locale]/messages.[locale].xlf` file and tra
4343

4444
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.
4545

46-
1. Add your locale, e.g. `fr` or `ja`, into `"languages"` array of `"xfillmergeOptions"` in `package.json` file.
47-
**Important: Locales should be written in lower case to be handled by Dashboard, e.g. `zh-tw`, not `zh-TW`**
48-
2. Run `npm run fix:i18n`. Then translation file for your language, e.g. `i18n/messages.fr.xlf`, would be generated.
49-
3. Create a new directory for generated file, e.g. `i18n/fr` and move generated file there.
46+
1. Create your locale directory under `i18n` directory, e.g. `i18n/fr` or `i18n/ja`.
47+
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.
48+
**Important: Locales should be written in lower case to be handled by Dashboard, e.g. `zh-cn`, not `zh-CN`**
49+
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.
50+
If `i18n/[locale]/messages.[locale].xlf` is not normal file type, our script ignores `xliffmerge` for the locale.
5051
4. Open your translation file and translate texts in `<target>` element into your language.
52+
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:
53+
```
54+
cd i18n/zh-cn
55+
ln -s ../zh/messages.zh.xlf messages.zh-cn.xlf
56+
```
5157

52-
After preparation of new translation file, configure `i18n/locale conf.json` file to build translated dashboard as follows:
58+
After preparation of new translation file, configure `i18n/locale_conf.json` file to support translated dashboard as follows:
5359

5460
```
5561
{"translations": [ "en", "fr", "ko", "zh" ]}
@@ -61,14 +67,21 @@ To add Japanese translation file, add `"ja"` into `"translations"` array in alph
6167
{"translations": [ "en", "fr", "ja", "ko", "zh" ]}
6268
```
6369

70+
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:
71+
72+
```
73+
fr
74+
ko
75+
```
76+
6477
Then you can build your localized dashboard with `npm run build`.
6578

6679
Before submit Pull Request, add `i18n/[locale]/OWNERS` file for your translation team like below:
6780

6881
```
6982
approvers:
7083
- [your github account]
71-
- [or your group name in kubernetes org]
84+
- [and more approvers' github account]
7285
7386
labels:
7487
- language/[your locale]

0 commit comments

Comments
 (0)