Skip to content

Commit

Permalink
feat(i18n): h5 titleNView buttons text
Browse files Browse the repository at this point in the history
  • Loading branch information
StrivingRabbit committed Feb 6, 2023
1 parent 14971f4 commit 91ca59b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/core/helpers/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ export function formatI18n (message) {
function resolveJsonObj (jsonObj, names) {
if (names.length === 1) {
if (jsonObj) {
const value = jsonObj[names[0]]
if (isStr(value) && isI18nStr(value, I18N_JSON_DELIMITERS)) {
const _isI18nStr = (value) => isStr(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[_name]
if (_isI18nStr(value)) {
return jsonObj
}
}
Expand All @@ -151,15 +156,21 @@ export function defineI18nProperty (obj, names) {
return false
}
const prop = names[names.length - 1]
let value = jsonObj[prop]
Object.defineProperty(jsonObj, prop, {
get () {
return formatI18n(value)
},
set (v) {
value = v
}
})
if (Array.isArray(jsonObj)) {
jsonObj
.filter(item => isI18nStr(item[prop], I18N_JSON_DELIMITERS))
.forEach(item => defineI18nProperty(item, [prop]))
} else {
let value = jsonObj[prop]
Object.defineProperty(jsonObj, prop, {
get () {
return formatI18n(value)
},
set (v) {
value = v
}
})
}
return true
}

Expand All @@ -171,7 +182,8 @@ export function initNavigationBarI18n (navigationBar) {
if (isEnableLocale()) {
return defineI18nProperties(navigationBar, [
['titleText'],
['searchInput', 'placeholder']
['searchInput', 'placeholder'],
['buttons', 'text']
])
}
}
Expand Down

0 comments on commit 91ca59b

Please sign in to comment.