提交 2cbc7d02 编写于 作者: fxy060608's avatar fxy060608

chore: tests

上级 52382584
...@@ -55,6 +55,29 @@ exports[`compileI18nJsonStr androidPrivacy.json 1`] = ` ...@@ -55,6 +55,29 @@ exports[`compileI18nJsonStr androidPrivacy.json 1`] = `
`; `;
exports[`compileI18nJsonStr pages.json->tabBar 1`] = ` exports[`compileI18nJsonStr pages.json->tabBar 1`] = `
"{
\\"color\\": \\"#7A7E83\\",
\\"selectedColor\\": \\"#007AFF\\",
\\"borderStyle\\": \\"black\\",
\\"backgroundColor\\": \\"#f8f8f8\\",
\\"list\\": [
{
\\"pagePath\\": \\"pages/tabBar/component/component\\",
\\"iconPath\\": \\"static/component.png\\",
\\"selectedIconPath\\": \\"static/componentHL.png\\",
\\"text\\": \\"组件\\"
},
{
\\"pagePath\\": \\"pages/tabBar/API/API\\",
\\"iconPath\\": \\"static/api.png\\",
\\"selectedIconPath\\": \\"static/apiHL.png\\",
\\"text\\": \\"接口\\"
}
]
}"
`;
exports[`compileI18nJsonStr pages.json->tabBar with multi language 1`] = `
"{ "{
\\"color\\": \\"#7A7E83\\", \\"color\\": \\"#7A7E83\\",
\\"selectedColor\\": \\"#007AFF\\", \\"selectedColor\\": \\"#007AFF\\",
......
...@@ -41,6 +41,43 @@ describe('compileI18nJsonStr', () => { ...@@ -41,6 +41,43 @@ describe('compileI18nJsonStr', () => {
).toBe('{}') ).toBe('{}')
}) })
test('pages.json->tabBar', () => { test('pages.json->tabBar', () => {
expect(
compileI18nJsonStr(
JSON.stringify({
color: '#7A7E83',
selectedColor: '#007AFF',
borderStyle: 'black',
backgroundColor: '#%tabBar.backgroundColor%',
list: [
{
pagePath: 'pages/tabBar/component/component',
iconPath: 'static/component.png',
selectedIconPath: 'static/componentHL.png',
text: '%tabBar.0.title%',
},
{
pagePath: 'pages/tabBar/API/API',
iconPath: 'static/api.png',
selectedIconPath: 'static/apiHL.png',
text: '%tabBar.1.title%',
},
],
}),
{
locale: 'zh-Hans',
locales: {
'zh-Hans': {
'tabBar.backgroundColor': 'f8f8f8',
'tabBar.0.title': '组件',
'tabBar.1.title': '接口',
},
},
delimiters,
}
)
).toMatchSnapshot()
})
test('pages.json->tabBar with multi language', () => {
expect( expect(
compileI18nJsonStr( compileI18nJsonStr(
JSON.stringify({ JSON.stringify({
...@@ -82,6 +119,7 @@ describe('compileI18nJsonStr', () => { ...@@ -82,6 +119,7 @@ describe('compileI18nJsonStr', () => {
) )
).toMatchSnapshot() ).toMatchSnapshot()
}) })
test('androidPrivacy.json', () => { test('androidPrivacy.json', () => {
expect( expect(
compileI18nJsonStr( compileI18nJsonStr(
......
...@@ -383,11 +383,13 @@ function compileValue(jsonObj, key, localeValues, delimiters) { ...@@ -383,11 +383,13 @@ function compileValue(jsonObj, key, localeValues, delimiters) {
// 存在国际化 // 存在国际化
if (isI18nStr(value, delimiters)) { if (isI18nStr(value, delimiters)) {
jsonObj[key] = compileStr(value, localeValues[0].values, delimiters); jsonObj[key] = compileStr(value, localeValues[0].values, delimiters);
// 格式化国际化语言 if (localeValues.length > 1) {
const valueLocales = (jsonObj[key + 'Locales'] = {}); // 格式化国际化语言
localeValues.forEach((localValue) => { const valueLocales = (jsonObj[key + 'Locales'] = {});
valueLocales[localValue.locale] = compileStr(value, localValue.values, delimiters); localeValues.forEach((localValue) => {
}); valueLocales[localValue.locale] = compileStr(value, localValue.values, delimiters);
});
}
} }
} }
else { else {
......
...@@ -379,11 +379,13 @@ function compileValue(jsonObj, key, localeValues, delimiters) { ...@@ -379,11 +379,13 @@ function compileValue(jsonObj, key, localeValues, delimiters) {
// 存在国际化 // 存在国际化
if (isI18nStr(value, delimiters)) { if (isI18nStr(value, delimiters)) {
jsonObj[key] = compileStr(value, localeValues[0].values, delimiters); jsonObj[key] = compileStr(value, localeValues[0].values, delimiters);
// 格式化国际化语言 if (localeValues.length > 1) {
const valueLocales = (jsonObj[key + 'Locales'] = {}); // 格式化国际化语言
localeValues.forEach((localValue) => { const valueLocales = (jsonObj[key + 'Locales'] = {});
valueLocales[localValue.locale] = compileStr(value, localValue.values, delimiters); localeValues.forEach((localValue) => {
}); valueLocales[localValue.locale] = compileStr(value, localValue.values, delimiters);
});
}
} }
} }
else { else {
......
...@@ -121,17 +121,19 @@ function compileValue( ...@@ -121,17 +121,19 @@ function compileValue(
localeValues[0].values, localeValues[0].values,
delimiters delimiters
) )
// 格式化国际化语言 if (localeValues.length > 1) {
const valueLocales: Record<string, string> = (( // 格式化国际化语言
jsonObj as Record<string | number, unknown> const valueLocales: Record<string, string> = ((
)[key + 'Locales'] = {}) jsonObj as Record<string | number, unknown>
localeValues.forEach((localValue) => { )[key + 'Locales'] = {})
valueLocales[localValue.locale] = compileStr( localeValues.forEach((localValue) => {
value, valueLocales[localValue.locale] = compileStr(
localValue.values, value,
delimiters localValue.values,
) delimiters
}) )
})
}
} }
} else { } else {
compileJsonObj(value, localeValues, delimiters) compileJsonObj(value, localeValues, delimiters)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册