feat: update zh-cn to zh-hans
Update zh-cn to zh-hans, and update the icon when switch language Change-Id: I3e6d3e8aebec4584f863282082a11b36d7cee193
This commit is contained in:
parent
f6347c1ff7
commit
a9370ef261
@ -19,7 +19,7 @@ module.exports = function (grunt) {
|
|||||||
src: ['src/**/*.{jsx,js}'],
|
src: ['src/**/*.{jsx,js}'],
|
||||||
dest: 'src',
|
dest: 'src',
|
||||||
options: {
|
options: {
|
||||||
lngs: ['en', 'zh', 'ko-kr'],
|
lngs: ['en', 'zh-hans', 'ko-kr'],
|
||||||
removeUnusedKeys: true,
|
removeUnusedKeys: true,
|
||||||
sort: true,
|
sort: true,
|
||||||
keySeparator: false,
|
keySeparator: false,
|
||||||
|
@ -79,7 +79,7 @@ Catalog Introduction
|
|||||||
├── local-storage-mock.js ( Storage mock function in local)
|
├── local-storage-mock.js ( Storage mock function in local)
|
||||||
├── locales (Translation files used when testing internationalization)
|
├── locales (Translation files used when testing internationalization)
|
||||||
│ ├── en-US.js
|
│ ├── en-US.js
|
||||||
│ └── zh-CN.js
|
│ └── zh-hans.js
|
||||||
├── setup-tests.js (setup uni test)
|
├── setup-tests.js (setup uni test)
|
||||||
└── svg-mock.js (Mock of image loading)
|
└── svg-mock.js (Mock of image loading)
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ test
|
|||||||
├── local-storage-mock.js ( Storage mock function in local)
|
├── local-storage-mock.js ( Storage mock function in local)
|
||||||
├── locales (Translation files used when testing internationalization)
|
├── locales (Translation files used when testing internationalization)
|
||||||
│ ├── en-US.js
|
│ ├── en-US.js
|
||||||
│ └── zh-CN.js
|
│ └── zh-hans.js
|
||||||
├── setup-tests.js (setup uni test)
|
├── setup-tests.js (setup uni test)
|
||||||
└── svg-mock.js (Mock of image loading)
|
└── svg-mock.js (Mock of image loading)
|
||||||
```
|
```
|
||||||
|
@ -77,7 +77,7 @@ test
|
|||||||
├── local-storage-mock.js (本地存储的mock函数)
|
├── local-storage-mock.js (本地存储的mock函数)
|
||||||
├── locales (测试国际化时使用的翻译文件)
|
├── locales (测试国际化时使用的翻译文件)
|
||||||
│ ├── en-US.js
|
│ ├── en-US.js
|
||||||
│ └── zh-CN.js
|
│ └── zh-hans.js
|
||||||
├── setup-tests.js (配置单元测试)
|
├── setup-tests.js (配置单元测试)
|
||||||
└── svg-mock.js (图片加载的mock)
|
└── svg-mock.js (图片加载的mock)
|
||||||
```
|
```
|
||||||
|
@ -68,7 +68,7 @@ export class AvatarDropdown extends React.Component {
|
|||||||
const { length } = SUPPORT_LOCALES;
|
const { length } = SUPPORT_LOCALES;
|
||||||
if (length > 3) {
|
if (length > 3) {
|
||||||
const options = SUPPORT_LOCALES.map((it) => ({
|
const options = SUPPORT_LOCALES.map((it) => ({
|
||||||
label: it.shortName.toLocaleUpperCase(),
|
label: it.icon.toLocaleUpperCase(),
|
||||||
value: it.value,
|
value: it.value,
|
||||||
}));
|
}));
|
||||||
return (
|
return (
|
||||||
@ -83,7 +83,7 @@ export class AvatarDropdown extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const btns = SUPPORT_LOCALES.map((item, index) => {
|
const btns = SUPPORT_LOCALES.map((item, index) => {
|
||||||
const { value, shortName } = item;
|
const { value, icon } = item;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
@ -94,7 +94,7 @@ export class AvatarDropdown extends React.Component {
|
|||||||
this.changeLang(value);
|
this.changeLang(value);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{shortName.toUpperCase()}
|
{icon.toUpperCase()}
|
||||||
</Button>
|
</Button>
|
||||||
{index !== length - 1 && <span>/</span>}
|
{index !== length - 1 && <span>/</span>}
|
||||||
</>
|
</>
|
||||||
|
@ -20,24 +20,26 @@ import SLI18n from 'utils/translate';
|
|||||||
import { setLocalStorageItem } from 'utils/local-storage';
|
import { setLocalStorageItem } from 'utils/local-storage';
|
||||||
import locales from '../locales';
|
import locales from '../locales';
|
||||||
|
|
||||||
|
// shortName: the i18n name in the api
|
||||||
|
// icon: the icon of switch language in ui
|
||||||
const SUPPORT_LOCALES = [
|
const SUPPORT_LOCALES = [
|
||||||
{
|
{
|
||||||
name: 'English',
|
name: 'English',
|
||||||
value: 'en',
|
value: 'en',
|
||||||
shortName: 'en',
|
shortName: 'en',
|
||||||
icon: 'us',
|
icon: 'en',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '简体中文',
|
name: '简体中文',
|
||||||
value: 'zh-cn',
|
value: 'zh-hans',
|
||||||
shortName: 'zh',
|
shortName: 'zh',
|
||||||
icon: 'cn',
|
icon: 'zh',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '한글',
|
name: '한글',
|
||||||
value: 'ko-kr',
|
value: 'ko-kr',
|
||||||
shortName: 'kr',
|
shortName: 'ko',
|
||||||
icon: 'kr',
|
icon: 'ko',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -96,12 +98,12 @@ const setLocale = (lang) => {
|
|||||||
return lang;
|
return lang;
|
||||||
};
|
};
|
||||||
|
|
||||||
const isLocaleZh = getLocale() === 'zh-cn';
|
const isLocaleZh = getLocale() === 'zh-hans';
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
const lang = getLocale();
|
const lang = getLocale();
|
||||||
|
|
||||||
if (lang === 'zh') {
|
if (lang === 'zh-hans') {
|
||||||
moment.locale('zh', {
|
moment.locale('zh', {
|
||||||
relativeTime: {
|
relativeTime: {
|
||||||
s: '1秒',
|
s: '1秒',
|
||||||
|
@ -12,12 +12,12 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import zhData from './zh.json';
|
import zhHansData from './zh-hans.json';
|
||||||
import enData from './en.json';
|
import enData from './en.json';
|
||||||
import krData from './ko-kr.json';
|
import krData from './ko-kr.json';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
'zh-cn': zhData,
|
'zh-hans': zhHansData,
|
||||||
en: enData,
|
en: enData,
|
||||||
'ko-kr': krData,
|
'ko-kr': krData,
|
||||||
};
|
};
|
||||||
|
@ -38,7 +38,7 @@ export const MODULE_KIND_MAP = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const LANG_MAP = {
|
export const LANG_MAP = {
|
||||||
zh: 'zh-cn',
|
'zh-hans': 'zh-hans',
|
||||||
en: 'en',
|
en: 'en',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class SLI18n {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.options = {
|
this.options = {
|
||||||
currentLocale: null, // Current locale such as 'en'
|
currentLocale: null, // Current locale such as 'en'
|
||||||
locales: {}, // app locale data like {"en":{"key1":"value1"},"zh-cn":{"key1":"值1"}}
|
locales: {}, // app locale data like {"en":{"key1":"value1"},"zh-hans":{"key1":"值1"}}
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
warningHandler: function warn(...msg) {
|
warningHandler: function warn(...msg) {
|
||||||
console.warn(...msg);
|
console.warn(...msg);
|
||||||
@ -179,7 +179,7 @@ class SLI18n {
|
|||||||
* Initialize properties and load CLDR locale data according to currentLocale
|
* Initialize properties and load CLDR locale data according to currentLocale
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @param {string} options.currentLocale Current locale such as 'en'
|
* @param {string} options.currentLocale Current locale such as 'en'
|
||||||
* @param {string} options.locales App locale data like {"en":{"key1":"value1"},"zh-cn":{"key1":"值1"}}
|
* @param {string} options.locales App locale data like {"en":{"key1":"value1"},"zh-hans":{"key1":"值1"}}
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
init(options = {}) {
|
init(options = {}) {
|
||||||
|
@ -13,19 +13,19 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import zhCN from '../../test/unit/locales/zh-CN';
|
import zhHans from '../../test/unit/locales/zh-hans';
|
||||||
import enUS from '../../test/unit/locales/en-US';
|
import enUS from '../../test/unit/locales/en-US';
|
||||||
import ReactIntlUniversal from './translate';
|
import ReactIntlUniversal from './translate';
|
||||||
|
|
||||||
const intl = new ReactIntlUniversal();
|
const intl = new ReactIntlUniversal();
|
||||||
const locales = {
|
const locales = {
|
||||||
'en-US': enUS,
|
'en-US': enUS,
|
||||||
'zh-CN': zhCN,
|
'zh-hans': zhHans,
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('test translate', () => {
|
describe('test translate', () => {
|
||||||
it('Set specific locale', () => {
|
it('Set specific locale', () => {
|
||||||
intl.init({ locales, currentLocale: 'zh-CN' });
|
intl.init({ locales, currentLocale: 'zh-hans' });
|
||||||
expect(intl.get('SIMPLE')).toBe('简单');
|
expect(intl.get('SIMPLE')).toBe('简单');
|
||||||
intl.init({ locales, currentLocale: 'en-US' });
|
intl.init({ locales, currentLocale: 'en-US' });
|
||||||
expect(intl.get('SIMPLE')).toBe('Simple');
|
expect(intl.get('SIMPLE')).toBe('Simple');
|
||||||
@ -178,7 +178,7 @@ describe('test translate', () => {
|
|||||||
})
|
})
|
||||||
).toBe('You have 10 photos.');
|
).toBe('You have 10 photos.');
|
||||||
|
|
||||||
intl.init({ locales, currentLocale: 'zh-CN' });
|
intl.init({ locales, currentLocale: 'zh-hans' });
|
||||||
expect(
|
expect(
|
||||||
intl.get('PHOTO', {
|
intl.get('PHOTO', {
|
||||||
num: 1,
|
num: 1,
|
||||||
@ -242,7 +242,7 @@ describe('test translate', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Uses fallback locale if key not found in currentLocale', () => {
|
it('Uses fallback locale if key not found in currentLocale', () => {
|
||||||
intl.init({ locales, currentLocale: 'zh-CN', fallbackLocale: 'en-US' });
|
intl.init({ locales, currentLocale: 'zh-hans', fallbackLocale: 'en-US' });
|
||||||
expect(intl.get('ONLY_IN_ENGLISH')).toBe('ONLY_IN_ENGLISH');
|
expect(intl.get('ONLY_IN_ENGLISH')).toBe('ONLY_IN_ENGLISH');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -14,11 +14,10 @@
|
|||||||
|
|
||||||
import getTitle from './common';
|
import getTitle from './common';
|
||||||
|
|
||||||
Cypress.Commands.add('setLanguage', () => {
|
Cypress.Commands.add('setLanguage', (value) => {
|
||||||
const exp = Date.now() + 864000000;
|
const exp = Date.now() + 864000000;
|
||||||
const language = Cypress.env('language') || 'zh';
|
const language = Cypress.env('language') || 'en';
|
||||||
const value = language === 'zh' ? 'zh-cn' : 'en';
|
const langValue = { value: value || language, expires: exp };
|
||||||
const langValue = { value, expires: exp };
|
|
||||||
window.localStorage.setItem('lang', JSON.stringify(langValue));
|
window.localStorage.setItem('lang', JSON.stringify(langValue));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -136,7 +135,7 @@ Cypress.Commands.add('clickMenu', (fatherIndex, sonIndex) => {
|
|||||||
|
|
||||||
Cypress.Commands.add('setLanguageByPage', () => {
|
Cypress.Commands.add('setLanguageByPage', () => {
|
||||||
const language = Cypress.env('language');
|
const language = Cypress.env('language');
|
||||||
if (language === 'zh') {
|
if (language === 'zh-hans') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cy.log('change language to english');
|
cy.log('change language to english');
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
const getTitle = (title) => {
|
const getTitle = (title) => {
|
||||||
const language = Cypress.env('language') || 'zh';
|
const language = Cypress.env('language') || 'en';
|
||||||
if (language === 'en') {
|
if (language === 'en') {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user