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

chore: tests

上级 52382584
......@@ -55,6 +55,29 @@ exports[`compileI18nJsonStr androidPrivacy.json 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\\",
\\"selectedColor\\": \\"#007AFF\\",
......
......@@ -41,6 +41,43 @@ describe('compileI18nJsonStr', () => {
).toBe('{}')
})
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(
compileI18nJsonStr(
JSON.stringify({
......@@ -82,6 +119,7 @@ describe('compileI18nJsonStr', () => {
)
).toMatchSnapshot()
})
test('androidPrivacy.json', () => {
expect(
compileI18nJsonStr(
......
......@@ -383,11 +383,13 @@ function compileValue(jsonObj, key, localeValues, delimiters) {
// 存在国际化
if (isI18nStr(value, delimiters)) {
jsonObj[key] = compileStr(value, localeValues[0].values, delimiters);
// 格式化国际化语言
const valueLocales = (jsonObj[key + 'Locales'] = {});
localeValues.forEach((localValue) => {
valueLocales[localValue.locale] = compileStr(value, localValue.values, delimiters);
});
if (localeValues.length > 1) {
// 格式化国际化语言
const valueLocales = (jsonObj[key + 'Locales'] = {});
localeValues.forEach((localValue) => {
valueLocales[localValue.locale] = compileStr(value, localValue.values, delimiters);
});
}
}
}
else {
......
......@@ -379,11 +379,13 @@ function compileValue(jsonObj, key, localeValues, delimiters) {
// 存在国际化
if (isI18nStr(value, delimiters)) {
jsonObj[key] = compileStr(value, localeValues[0].values, delimiters);
// 格式化国际化语言
const valueLocales = (jsonObj[key + 'Locales'] = {});
localeValues.forEach((localValue) => {
valueLocales[localValue.locale] = compileStr(value, localValue.values, delimiters);
});
if (localeValues.length > 1) {
// 格式化国际化语言
const valueLocales = (jsonObj[key + 'Locales'] = {});
localeValues.forEach((localValue) => {
valueLocales[localValue.locale] = compileStr(value, localValue.values, delimiters);
});
}
}
}
else {
......
......@@ -121,17 +121,19 @@ function compileValue(
localeValues[0].values,
delimiters
)
// 格式化国际化语言
const valueLocales: Record<string, string> = ((
jsonObj as Record<string | number, unknown>
)[key + 'Locales'] = {})
localeValues.forEach((localValue) => {
valueLocales[localValue.locale] = compileStr(
value,
localValue.values,
delimiters
)
})
if (localeValues.length > 1) {
// 格式化国际化语言
const valueLocales: Record<string, string> = ((
jsonObj as Record<string | number, unknown>
)[key + 'Locales'] = {})
localeValues.forEach((localValue) => {
valueLocales[localValue.locale] = compileStr(
value,
localValue.values,
delimiters
)
})
}
}
} else {
compileJsonObj(value, localeValues, delimiters)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册