2020-01-24 23:59:16 +01:00
|
|
|
---
|
|
|
|
title: Developing for Internationalization
|
|
|
|
---
|
2020-01-15 15:57:54 +01:00
|
|
|
|
2020-01-24 23:59:16 +01:00
|
|
|
{{< note >}}
|
|
|
|
All the files you created should use UTF-8 encoding.
|
|
|
|
{{< /note >}}
|
2019-10-17 15:47:25 +02:00
|
|
|
|
2020-01-15 15:57:54 +01:00
|
|
|
Steps to localize the UI in your language
|
2019-10-17 15:47:25 +02:00
|
|
|
|
|
|
|
1. In the folder `src/portal/src/i18n/lang`, copy json file `en-us-lang.json` to a new file and rename it to `<language>-<locale>-lang.json` .
|
|
|
|
|
|
|
|
The file contains a JSON object including all the key-value pairs of UI strings:
|
2020-01-24 23:59:16 +01:00
|
|
|
|
2020-01-27 19:15:44 +01:00
|
|
|
```javascript
|
2019-10-17 15:47:25 +02:00
|
|
|
{
|
2020-01-27 19:15:44 +01:00
|
|
|
"APP_TITLE": {
|
|
|
|
"VMW_HARBOR": "Harbor",
|
|
|
|
"HARBOR": "Harbor",
|
|
|
|
// ...
|
|
|
|
},
|
|
|
|
// ...
|
2019-10-17 15:47:25 +02:00
|
|
|
}
|
2020-01-24 23:59:16 +01:00
|
|
|
```
|
|
|
|
|
2019-10-17 15:47:25 +02:00
|
|
|
In the file `<language>-<locale>-lang.json`, translate all the values into your language. Do not change any keys.
|
|
|
|
|
|
|
|
2. After creating your language file, you should add it to the language supporting list.
|
|
|
|
|
|
|
|
Locate the file `src/portal/src/app/shared/shared.const.ts`.
|
2020-01-24 23:59:16 +01:00
|
|
|
|
2019-10-17 15:47:25 +02:00
|
|
|
Append `<language>-<locale>` to the language supporting list:
|
2020-01-24 23:59:16 +01:00
|
|
|
|
2020-01-27 19:15:44 +01:00
|
|
|
```typescript
|
2019-10-17 15:47:25 +02:00
|
|
|
export const supportedLangs = ['en-us', 'zh-cn', '<language>-<locale>'];
|
|
|
|
```
|
2020-01-27 19:15:44 +01:00
|
|
|
|
2019-10-17 15:47:25 +02:00
|
|
|
Define the language display name and append it to the name list:
|
2020-01-24 23:59:16 +01:00
|
|
|
|
2020-01-27 19:15:44 +01:00
|
|
|
```typescript
|
2019-10-17 15:47:25 +02:00
|
|
|
export const languageNames = {
|
|
|
|
"en-us": "English",
|
|
|
|
"zh-cn": "中文简体",
|
|
|
|
"<language>-<locale>": "<DISPLAY_NAME>"
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
2020-01-27 19:15:44 +01:00
|
|
|
{{< note >}}
|
|
|
|
Don't miss the comma before the new key-value item you've added.
|
|
|
|
{{< /note >}}
|
2019-10-17 15:47:25 +02:00
|
|
|
|
|
|
|
3. Enable the new language in the view.
|
|
|
|
|
|
|
|
Locate the file `src/portal/src/app/base/navigator/navigator.component.html` and then find the following code piece:
|
2020-01-24 23:59:16 +01:00
|
|
|
|
|
|
|
```html
|
2019-10-17 15:47:25 +02:00
|
|
|
<div class="dropdown-menu">
|
2020-01-27 19:15:44 +01:00
|
|
|
<a href="javascript:void(0)" clrDropdownItem (click)='switchLanguage("en-us")' [class.lang-selected]='matchLang("en-us")'>English</a>
|
|
|
|
<a href="javascript:void(0)" clrDropdownItem (click)='switchLanguage("zh-cn")' [class.lang-selected]='matchLang("zh-cn")'>中文简体</a>
|
2019-10-17 15:47:25 +02:00
|
|
|
</div>
|
|
|
|
```
|
2020-01-24 23:59:16 +01:00
|
|
|
|
|
|
|
Add a new menu item for your language:
|
|
|
|
|
|
|
|
```html
|
2019-10-17 15:47:25 +02:00
|
|
|
<div class="dropdown-menu">
|
2020-01-27 19:15:44 +01:00
|
|
|
<a href="javascript:void(0)" clrDropdownItem (click)='switchLanguage("en-us")' [class.lang-selected]='matchLang("en-us")'>English</a>
|
|
|
|
<a href="javascript:void(0)" clrDropdownItem (click)='switchLanguage("zh-cn")' [class.lang-selected]='matchLang("zh-cn")'>中文简体</a>
|
|
|
|
<a href="javascript:void(0)" clrDropdownItem (click)='switchLanguage("<language>-<locale>")' [class.lang-selected]='matchLang("<language>-<locale>")'>DISPLAY_NAME</a>
|
2019-10-17 15:47:25 +02:00
|
|
|
</div>
|
|
|
|
```
|
|
|
|
|
2020-02-20 13:02:41 +01:00
|
|
|
4. Next, refer to [Build Harbor from Source Code](compile-guide.md) to rebuild and restart Harbor.
|