提交 318147aa 编写于 作者: fxy060608's avatar fxy060608

wip(i18n): h5 titleText

上级 fd8d558f
......@@ -431,7 +431,7 @@ function traverseRenderList (callExprNode, state) {
const isBaidu = state.options.platform.name === 'mp-baidu'
let forValue = genCode(callExprNode.arguments[0], isBaidu)
if(isBaidu && forKey) {
if (isBaidu && forKey) {
forValue += ` trackBy ${getForKey(forKey, forIndex, state)}`
}
......
......@@ -444,6 +444,7 @@ module.exports = function (pagesJson, manifestJson, loader) {
return `
import Vue from 'vue'
${genLayoutComponentsCode(pagesJson)}
const locales = ${fs.existsSync(path.resolve(process.env.UNI_INPUT_DIR, 'locale')) ? 'require.context(\'./locale\', false, /\.json$/)' : '{keys(){return []}}'}
global['____${h5.appid}____'] = true;
delete global['____${h5.appid}____'];
global.__uniConfig = ${JSON.stringify(pagesJson)};
......@@ -456,10 +457,12 @@ global.__uniConfig.networkTimeout = ${JSON.stringify(networkTimeoutConfig)};
global.__uniConfig.sdkConfigs = ${JSON.stringify(sdkConfigs)};
global.__uniConfig.qqMapKey = ${JSON.stringify(qqMapKey)};
global.__uniConfig.locale = ${JSON.stringify(locale)};
global.__uniConfig.fallbackLocale = ${JSON.stringify(manifestJson.fallbackLocale)};
global.__uniConfig.locales = locales.keys().reduce((res,key)=>{res[key.replace(/\\.\\/(.*).json/,'$1')]=locales(key);return res},{});
global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection(manifestJson['app-plus']) })}
global.__uniConfig.__webpack_chunk_load__ = __webpack_chunk_load__
${genRegisterPageVueComponentsCode(pageComponents)}
global.__uniRoutes=[${genPageRoutes(pageComponents).concat(genSystemRoutes()).join(',')}]
global.UniApp && new global.UniApp();
`
}
}
import {
initVueI18n
initVueI18n,
isI18nStr
} from '@dcloudio/uni-i18n'
import {
isStr
} from 'uni-shared'
import en from './en.json'
import es from './es.json'
......@@ -65,4 +69,89 @@ export function initAppLocale (Vue, appVm, locale) {
localeWatchers.forEach(watch => watch(v))
}
})
}
export const I18N_JSON_DELIMITERS = ['%', '%']
function getLocaleMessage () {
const locale = uni.getLocale()
const locales = __uniConfig.locales
return (
locales[locale] || locales[__uniConfig.fallbackLocale] || locales.en || {}
)
}
export function formatI18n (message) {
if (isI18nStr(message, I18N_JSON_DELIMITERS)) {
return i18n.f(message, getLocaleMessage(), I18N_JSON_DELIMITERS)
}
return message
}
function resolveJsonObj (
jsonObj,
names
) {
if (names.length === 1) {
if (jsonObj) {
const value = jsonObj[names[0]]
if (isStr(value) && isI18nStr(value, I18N_JSON_DELIMITERS)) {
return jsonObj
}
}
return
}
const name = names.shift()
return resolveJsonObj(jsonObj && jsonObj[name], names)
}
export function defineI18nProperties (
obj,
names
) {
return names.map((name) => defineI18nProperty(obj, name))
}
export function defineI18nProperty (obj, names) {
const jsonObj = resolveJsonObj(obj, names)
if (!jsonObj) {
return false
}
const prop = names[names.length - 1]
let value = jsonObj[prop]
Object.defineProperty(jsonObj, prop, {
get () {
return formatI18n(value)
},
set (v) {
value = v
}
})
return true
}
function isEnableLocale () {
return __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
}
export function initNavigationBarI18n (navigationBar) {
if (isEnableLocale()) {
return defineI18nProperties(navigationBar, [
['titleText'],
['searchInput', 'placeholder']
])
}
}
export function initPullToRefreshI18n (
pullToRefresh
) {
if (isEnableLocale()) {
const CAPTION = 'caption'
return defineI18nProperties(pullToRefresh, [
['contentdown', CAPTION],
['contentover', CAPTION],
['contentrefresh', CAPTION]
])
}
}
......@@ -7,7 +7,7 @@
<page-refresh
v-if="enablePullDownRefresh"
ref="refresh"
:color="refreshOptions.color"
:color="refreshOptions.color"
:offset="refreshOptions.offset"
/>
<page-body
......@@ -35,7 +35,9 @@
import {
upx2px
} from 'uni-helpers/index'
import {
initNavigationBarI18n
} from 'uni-helpers/i18n'
import {
NAVBAR_HEIGHT
} from 'uni-helpers/constants'
......@@ -216,7 +218,7 @@ export default {
titlePenetrate: yesNoParseList[this.titlePenetrate]
}, titleNView)
navigationBar.shadow = this.navigationBarShadow
initNavigationBarI18n(navigationBar)
const refreshOptions = Object.assign({
support: true,
color: '#2BD009',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册