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

wip(i18n): Compatible with vue2

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