提交 470a06e1 编写于 作者: fxy060608's avatar fxy060608

wip(i18n): Compatible with vue2

上级 2cbc7d02
......@@ -25,8 +25,6 @@ export const setLocale = defineSyncApi<typeof uni.setLocale>(
const oldLocale = getApp().$vm.$locale
if (oldLocale !== locale) {
getApp().$vm.$locale = locale
// 执行 uni.onLocaleChange
UniServiceJSBridge.invokeOnCallback(API_ON_LOCALE_CHANGE, { locale })
if (__PLATFORM__ === 'app') {
const pages = getCurrentPages()
pages.forEach((page) => {
......@@ -38,6 +36,8 @@ export const setLocale = defineSyncApi<typeof uni.setLocale>(
})
weex.requireModule('plus').setLanguage(locale)
}
// 执行 uni.onLocaleChange
UniServiceJSBridge.invokeOnCallback(API_ON_LOCALE_CHANGE, { locale })
return true
}
return false
......
......@@ -10470,9 +10470,7 @@ function createPageHeadSearchInputTsx(navigationBar, {
"style": {
color
},
"placeholder-style": {
color: placeholderColor
},
"placeholder-style": "color: " + placeholderColor,
"class": "uni-page-head-search-input",
"confirm-type": "search",
"onClick": onClick
......@@ -10481,9 +10479,7 @@ function createPageHeadSearchInputTsx(navigationBar, {
"style": {
color
},
"placeholder-style": {
color: placeholderColor
},
"placeholder-style": "color: " + placeholderColor,
"class": "uni-page-head-search-input",
"confirm-type": "search",
"onFocus": onFocus,
......
......@@ -20828,9 +20828,7 @@ function createPageHeadSearchInputTsx(navigationBar, {
"style": {
color
},
"placeholder-style": {
color: placeholderColor
},
"placeholder-style": "color: " + placeholderColor,
"class": "uni-page-head-search-input",
"confirm-type": "search",
"onClick": onClick
......@@ -20839,9 +20837,7 @@ function createPageHeadSearchInputTsx(navigationBar, {
"style": {
color
},
"placeholder-style": {
color: placeholderColor
},
"placeholder-style": "color: " + placeholderColor,
"class": "uni-page-head-search-input",
"confirm-type": "search",
"onFocus": onFocus,
......
......@@ -220,7 +220,7 @@ function createPageHeadSearchInputTsx(
<Input
disabled={true}
style={{ color }}
placeholder-style={{ color: placeholderColor }}
placeholder-style={'color: ' + placeholderColor}
class="uni-page-head-search-input"
confirm-type="search"
onClick={onClick}
......@@ -229,7 +229,7 @@ function createPageHeadSearchInputTsx(
<Input
focus={autoFocus}
style={{ color }}
placeholder-style={{ color: placeholderColor }}
placeholder-style={'color: ' + placeholderColor}
class="uni-page-head-search-input"
confirm-type="search"
onFocus={onFocus}
......
......@@ -223,9 +223,18 @@ class I18n {
const ignoreVueI18n = true;
function watchAppLocale(appVm, i18n) {
appVm.$watch(() => appVm.$locale, (newLocale) => {
i18n.setLocale(newLocale);
});
// 需要保证 watch 的触发在组件渲染之前
if (appVm.$watchLocale) {
// vue2
appVm.$watchLocale((newLocale) => {
i18n.setLocale(newLocale);
});
}
else {
appVm.$watch(() => appVm.$locale, (newLocale) => {
i18n.setLocale(newLocale);
});
}
}
function initVueI18n(locale, messages = {}, fallbackLocale, watcher) {
// 兼容旧版本入参
......
......@@ -219,9 +219,18 @@ class I18n {
const ignoreVueI18n = true;
function watchAppLocale(appVm, i18n) {
appVm.$watch(() => appVm.$locale, (newLocale) => {
i18n.setLocale(newLocale);
});
// 需要保证 watch 的触发在组件渲染之前
if (appVm.$watchLocale) {
// vue2
appVm.$watchLocale((newLocale) => {
i18n.setLocale(newLocale);
});
}
else {
appVm.$watch(() => appVm.$locale, (newLocale) => {
i18n.setLocale(newLocale);
});
}
}
function initVueI18n(locale, messages = {}, fallbackLocale, watcher) {
// 兼容旧版本入参
......
......@@ -14,12 +14,20 @@ type Interpolate = (
) => string
function watchAppLocale(appVm: any, i18n: I18n) {
appVm.$watch(
() => appVm.$locale,
(newLocale: string) => {
// 需要保证 watch 的触发在组件渲染之前
if (appVm.$watchLocale) {
// vue2
appVm.$watchLocale((newLocale: string) => {
i18n.setLocale(newLocale)
}
)
})
} else {
appVm.$watch(
() => appVm.$locale,
(newLocale: string) => {
i18n.setLocale(newLocale)
}
)
}
}
// function getDefaultLocale() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册