Skip to content

Commit

Permalink
Fix locale mapping (#4969)
Browse files Browse the repository at this point in the history
* Fix locale mapping

Now, Angular>=9.0.5 supports `zh-Hant-HK` and `zh-Hans-SG`, so we can build for them.
Also, `Match` of `golang.org/x/text/language` returns `zh-u-rg-cnzzzz` for `zh-CN` and
`zh-u-rg-txzzzz` for `zh-TW`, so we need to handle them properly before.

Since `Match` returns tag as `zh-Hant-HK` for `zh-HK`, and `zh-Hans-SG` for `zh-SG`,
so dashboard just use them.

However due to following reason, remove `zh-Hant-SG` and `zh` support for now.
* Chinese is not official in Singapore
* `zh` is not used often
* Translation files for `zh` and `zh-Hans-SG` is same as `zh-Hant` for now.

In conclusion, dashboard supports strictly matched locale IDs as followings:
* en (default)
* de
* fr
* ja
* ko
* zh-CN (zh-Hans)
* zh-TW (zh-Hant)
* zh-HK (zh-Hant-HK)

Also, support locales in lowercase and clean up `state="new"` in some translation files.

* Simplify locale matching logic

Co-authored-by: Sebastian Florek <sebastian.florek@loodse.com>
  • Loading branch information
shu-mutou and Sebastian Florek committed Apr 9, 2020
1 parent bd741a0 commit 6ab57ed
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 10,653 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ 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/

Expand Down
8 changes: 4 additions & 4 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
"translation": "i18n/ko/messages.ko.xlf",
"baseHref": ""
},
"zh": {
"translation": "i18n/zh/messages.zh.xlf",
"baseHref": ""
},
"zh-Hans": {
"translation": "i18n/zh-Hans/messages.zh-Hans.xlf",
"baseHref": ""
},
"zh-Hant": {
"translation": "i18n/zh-Hant/messages.zh-Hant.xlf",
"baseHref": ""
},
"zh-Hant-HK": {
"translation": "i18n/zh-Hant-HK/messages.zh-Hant-HK.xlf",
"baseHref": ""
}
}
},
Expand Down
44 changes: 18 additions & 26 deletions docs/developer/internationalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

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 | Remarks |
|---------------------|---------|------------|
| English (default) | en | - |
| French | fr | - |
| German | de | - |
| 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 | - |
| Language | Code | Remarks |
|---------------------|------------|-----------------|
| English (default) | en | - |
| French | fr | - |
| German | de | - |
| Japanese | ja | - |
| Korean | ko | - |
| Simplified Chinese | zh-Hans | - |
| Traditional Chinese | zh-Hant | - |
| Traditional Chinese (Hong Kong) | zh-Hant-HK | - |

## Building localized dashboard

Expand Down Expand Up @@ -45,16 +43,17 @@ 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. 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`**
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 using an existing translation file, i.e. add `zh` but use existing `i18n/zh-Hans/messages.zh-Hans.xlf` file for it, skip this step and go step 5.
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:
4. Open your translation file and translate texts in `<target>` element into your language, and remove `state="new"` to mark it as translated.
5. To build dashboard for your language, add your locale into `locales` in `angular.json` like follow:
```
cd i18n/zh-cn
ln -s ../zh/messages.zh.xlf messages.zh-cn.xlf
"ja": {
"translation": "i18n/ja/messages.ja.xlf",
"baseHref": ""
},
```
If you want to add only locale using an existing translation file, specify existing translation file to `"translation"`.

After preparation of new translation file, configure `i18n/locale_conf.json` file to support translated dashboard as follows:

Expand All @@ -68,13 +67,6 @@ 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:
Expand Down
6 changes: 3 additions & 3 deletions i18n/ko/messages.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{resource.displayName}}"/>
</source>
<target state="new"><x id="INTERPOLATION" equiv-text="{{resource.displayName}}"/>
<target><x id="INTERPOLATION" equiv-text="{{resource.displayName}}"/>
</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/chrome/nav/pinner/template.html</context>
Expand Down Expand Up @@ -5152,15 +5152,15 @@
</trans-unit>
<trans-unit id="a4f3393592e5ebfd34408e85c3bd576d88839191" datatype="html">
<source>Disable access denied notification</source>
<target state="new">접근 거부 알림 해제</target>
<target>접근 거부 알림 해제</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/settings/global/template.html</context>
<context context-type="linenumber">100</context>
</context-group>
</trans-unit>
<trans-unit id="b6484080715a11bad65395e51d42e6ae4aa3c856" datatype="html">
<source>Hides all access denied warnings in the notification panel.</source>
<target state="new">알림 패널에서 접근 거부 경고 모두 숨김.</target>
<target>알림 패널에서 접근 거부 경고 모두 숨김.</target>
<context-group purpose="location">
<context context-type="sourcefile">../src/app/frontend/settings/global/template.html</context>
<context context-type="linenumber">102</context>
Expand Down
2 changes: 1 addition & 1 deletion i18n/locale_conf.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translations": [ "de", "en", "fr", "ja", "ko", "zh", "zh-Hans", "zh-Hant-HK", "zh-Hans-SG", "zh-Hant" ]}
{"translations": [ "de", "en", "fr", "ja", "ko", "zh-Hans", "zh-Hant", "zh-Hant-HK" ]}
10 changes: 0 additions & 10 deletions i18n/zh-Hans-SG/OWNERS

This file was deleted.

Loading

0 comments on commit 6ab57ed

Please sign in to comment.