提交 3c47420f 编写于 作者: D DCloud_LXH

feat(i18n): h5 titleNView buttons text

上级 2b84f65d
...@@ -8,6 +8,7 @@ export function initNavigationBarI18n( ...@@ -8,6 +8,7 @@ export function initNavigationBarI18n(
return defineI18nProperties(navigationBar, [ return defineI18nProperties(navigationBar, [
['titleText'], ['titleText'],
['searchInput', 'placeholder'], ['searchInput', 'placeholder'],
['buttons', 'text'],
]) as [boolean, boolean] ]) as [boolean, boolean]
} }
} }
......
...@@ -31,9 +31,18 @@ export function formatI18n(message: string) { ...@@ -31,9 +31,18 @@ export function formatI18n(message: string) {
function resolveJsonObj( function resolveJsonObj(
jsonObj: Record<string, any> | undefined, jsonObj: Record<string, any> | undefined,
names: string[] names: string[]
): Record<string, any> | undefined { ): Record<string, any> | Array<Record<string, any>> | undefined {
if (names.length === 1) { if (names.length === 1) {
if (jsonObj) { if (jsonObj) {
const _isI18nStr = (value: any) =>
isString(value) && isI18nStr(value, I18N_JSON_DELIMITERS)
const _name = names[0]
if (
Array.isArray(jsonObj) &&
jsonObj.some((item) => _isI18nStr(item[_name]))
) {
return jsonObj
}
const value = jsonObj[names[0]] const value = jsonObj[names[0]]
if (isString(value) && isI18nStr(value, I18N_JSON_DELIMITERS)) { if (isString(value) && isI18nStr(value, I18N_JSON_DELIMITERS)) {
return jsonObj return jsonObj
...@@ -58,6 +67,11 @@ export function defineI18nProperty(obj: Record<string, any>, names: string[]) { ...@@ -58,6 +67,11 @@ export function defineI18nProperty(obj: Record<string, any>, names: string[]) {
return false return false
} }
const prop = names[names.length - 1] const prop = names[names.length - 1]
if (Array.isArray(jsonObj)) {
jsonObj
.filter((item) => isI18nStr(item[prop], I18N_JSON_DELIMITERS))
.forEach((item) => defineI18nProperty(item, [prop]))
} else {
let value = jsonObj[prop] let value = jsonObj[prop]
Object.defineProperty(jsonObj, prop, { Object.defineProperty(jsonObj, prop, {
get() { get() {
...@@ -67,6 +81,7 @@ export function defineI18nProperty(obj: Record<string, any>, names: string[]) { ...@@ -67,6 +81,7 @@ export function defineI18nProperty(obj: Record<string, any>, names: string[]) {
value = v value = v
}, },
}) })
}
return true return true
} }
......
...@@ -363,7 +363,8 @@ function usePageHeadButton( ...@@ -363,7 +363,8 @@ function usePageHeadButton(
if (btn.fontFamily) { if (btn.fontFamily) {
iconStyle.fontFamily = btn.fontFamily iconStyle.fontFamily = btn.fontFamily
} }
return { return new Proxy(
{
btnClass: { btnClass: {
// 类似这样的大量重复的字符串,会在gzip时压缩大小,无需在代码层考虑优化相同字符串 // 类似这样的大量重复的字符串,会在gzip时压缩大小,无需在代码层考虑优化相同字符串
'uni-page-head-btn': true, 'uni-page-head-btn': true,
...@@ -374,8 +375,7 @@ function usePageHeadButton( ...@@ -374,8 +375,7 @@ function usePageHeadButton(
backgroundColor: isTransparent ? btn.background : 'transparent', backgroundColor: isTransparent ? btn.background : 'transparent',
width: btn.width, width: btn.width,
}, },
btnText: btnText: '',
btn.fontSrc && btn.fontFamily ? btn.text.replace('\\u', '&#x') : btn.text,
btnIconPath: ICON_PATHS[btn.type], btnIconPath: ICON_PATHS[btn.type],
badgeText: btn.badgeText, badgeText: btn.badgeText,
iconStyle, iconStyle,
...@@ -383,7 +383,19 @@ function usePageHeadButton( ...@@ -383,7 +383,19 @@ function usePageHeadButton(
invokeHook(pageId, ON_NAVIGATION_BAR_BUTTON_TAP, extend({ index }, btn)) invokeHook(pageId, ON_NAVIGATION_BAR_BUTTON_TAP, extend({ index }, btn))
}, },
btnSelect: btn.select, btnSelect: btn.select,
},
{
get(target, key, receiver) {
if (['btnText'].includes(key as string)) {
return btn.fontSrc && btn.fontFamily
? btn.text.replace('\\u', '&#x')
: btn.text
} else {
return Reflect.get(target, key, receiver)
}
},
} }
)
} }
type PageHeadSearchInput = ReturnType<typeof usePageHeadSearchInput> type PageHeadSearchInput = ReturnType<typeof usePageHeadSearchInput>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册