提交 36b699b3 编写于 作者: fxy060608's avatar fxy060608

wip(i18n): tabBar

上级 894e0d3b
......@@ -21,10 +21,10 @@ export function uniMainJsPlugin() {
}
function createApp(code: string) {
return `const __app__=createApp().app;__app__._component.mpType='app';__app__._component.render=()=>{};__app__.use(uni.__vuePlugin).mount("#app");${code.replace(
return `${code.replace(
'createSSRApp',
'createVueApp as createSSRApp'
)}`
)};const __app__=createApp().app;__app__._component.mpType='app';__app__._component.render=()=>{};__app__.use(uni.__vuePlugin).mount("#app");`
}
function createLegacyApp(code: string) {
......
import { compileI18nJsonStr } from '@dcloudio/uni-i18n'
import { M } from '../../../messages'
import { initI18nOptions } from '../../../i18n'
export function initI18n(
manifestJson: Record<string, any>,
userManifestJson: Record<string, any>
) {
const i18nOptions = initI18nOptions(
process.env.UNI_INPUT_DIR,
userManifestJson.fallbackLocale
)
let fallbackLocale: string | undefined = undefined
if (i18nOptions) {
fallbackLocale = i18nOptions.locale
if (!userManifestJson.fallbackLocale) {
console.warn(
M['i18n.fallbackLocale.missing'].replace('{locale}', fallbackLocale)
)
} else if (userManifestJson.fallbackLocale !== fallbackLocale) {
console.warn(
M['i18n.fallbackLocale.unmatch'].replace(
'{locale}',
userManifestJson.fallbackLocale
)
)
}
if (manifestJson.plus.tabBar) {
manifestJson.plus.tabBar = JSON.parse(
compileI18nJsonStr(
JSON.stringify(manifestJson.plus.tabBar),
i18nOptions
)
)
}
manifestJson.fallbackLocale = fallbackLocale
}
}
......@@ -10,6 +10,7 @@ import { initConfusion } from './confusion'
import { initUniApp } from './uniApp'
import { initLaunchwebview } from './launchwebview'
import { initTabBar } from './tabBar'
import { initI18n } from './i18n'
export function normalizeAppManifestJson(
userManifestJson: Record<string, any>,
......@@ -32,6 +33,7 @@ export function normalizeAppManifestJson(
manifestJson,
pagesJson
)
initI18n(manifestJson, userManifestJson)
return manifestJson
}
......
import { recursive } from 'merge'
import { M } from '../../../messages'
import { initI18nOptions } from '../../../i18n'
export function initRecursiveMerge(
manifestJson: Record<string, any>,
userManifestJson: Record<string, any>
): Record<string, any> {
const i18nOptions = initI18nOptions(
process.env.UNI_INPUT_DIR,
userManifestJson.fallbackLocale
)
let fallbackLocale: string | undefined = undefined
if (i18nOptions) {
fallbackLocale = i18nOptions.locale
if (!userManifestJson.fallbackLocale) {
console.warn(
M['i18n.fallbackLocale.missing'].replace('{locale}', fallbackLocale)
)
} else if (userManifestJson.fallbackLocale !== fallbackLocale) {
console.warn(
M['i18n.fallbackLocale.unmatch'].replace(
'{locale}',
userManifestJson.fallbackLocale
)
)
}
}
return recursive(
true,
manifestJson,
......@@ -38,7 +16,6 @@ export function initRecursiveMerge(
code: userManifestJson.versionCode,
},
locale: userManifestJson.locale,
fallbackLocale,
},
{ plus: userManifestJson['app-plus'] }
)
......
......@@ -15,5 +15,5 @@ export const M = {
'i18n.fallbackLocale.missing':
'当前应用未在manifest.json配置fallbackLocale,默认使用:{locale}',
'i18n.fallbackLocale.unmatch':
'当前应用配置的fallbackLocale为:${locale},但locale目录缺少该语言文件',
'当前应用配置的fallbackLocale为:{locale},但locale目录缺少该语言文件',
}
......@@ -37,10 +37,10 @@ export function uniMainJsPlugin() {
}
function createApp(code: string) {
return `import { plugin as __plugin } from '@dcloudio/uni-h5';createApp().app.use(__plugin).mount("#app");${code.replace(
return `import { plugin as __plugin } from '@dcloudio/uni-h5';${code.replace(
'createSSRApp',
'createVueApp as createSSRApp'
)}`
)};createApp().app.use(__plugin).mount("#app");`
}
function createLegacyApp(code: string) {
......@@ -51,7 +51,7 @@ function createLegacyApp(code: string) {
}
function createSSRClientApp(code: string) {
return `import { plugin as __plugin } from '@dcloudio/uni-h5';import { UNI_SSR, UNI_SSR_STORE } from '@dcloudio/uni-shared';const { app: __app, store: __store } = createApp();__app.use(__plugin);__store && window[UNI_SSR] && window[UNI_SSR][UNI_SSR_STORE] && __store.replaceState(window[UNI_SSR][UNI_SSR_STORE]);__app.router.isReady().then(() => __app.mount("#app"));${code}`
return `import { plugin as __plugin } from '@dcloudio/uni-h5';import { UNI_SSR, UNI_SSR_STORE } from '@dcloudio/uni-shared';${code};const { app: __app, store: __store } = createApp();__app.use(__plugin);__store && window[UNI_SSR] && window[UNI_SSR][UNI_SSR_STORE] && __store.replaceState(window[UNI_SSR][UNI_SSR_STORE]);__app.router.isReady().then(() => __app.mount("#app"));`
}
function createSSRServerApp(code: string) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册