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

wip(i18n): tabBar

上级 8a88f513
......@@ -18,7 +18,7 @@ export function uniOptions(): UniVitePlugin['uni'] {
src: 'androidPrivacy.json',
dest: outputDir,
transform(source) {
const options = initI18nOptions(platfrom, inputDir)
const options = initI18nOptions(platfrom, inputDir, false, true)
if (!options) {
return
}
......
......@@ -23,10 +23,10 @@ export function initI18nOptions(
)
if (warning) {
if (!fallbackLocale) {
console.warn(M['i18n.fallbackLocale.missing'].replace('{locale}', locale))
console.warn(M['i18n.fallbackLocale.default'].replace('{locale}', locale))
} else if (locale !== fallbackLocale) {
console.warn(
M['i18n.fallbackLocale.unmatch'].replace('{locale}', fallbackLocale)
M['i18n.fallbackLocale.missing'].replace('{locale}', fallbackLocale)
)
}
}
......@@ -39,7 +39,7 @@ export function initI18nOptions(
export const initI18nOptionsOnce = once(initI18nOptions)
function initLocales(dir: string, withMessages: boolean = true) {
export function initLocales(dir: string, withMessages: boolean = true) {
if (!fs.existsSync(dir)) {
return {}
}
......@@ -63,18 +63,12 @@ function resolveI18nLocale(
if (locale && locales.includes(locale)) {
return locale
}
let defaultFallbackLocale = 'en'
const defaultLocales = ['zh-Hans', 'zh-Hant']
if (platfrom === 'app' || platfrom === 'h5') {
defaultLocales.unshift('en')
} else {
// 小程序
defaultLocales.push('en')
defaultFallbackLocale = 'zh-Hans'
}
return (
defaultLocales.find((locale) => locales.includes(locale)) ||
locales[0] ||
defaultFallbackLocale
)
return defaultLocales.find((locale) => locales.includes(locale)) || locales[0]
}
import path from 'path'
import { initLocales } from '../../../i18n'
import { normalizeNetworkTimeout } from '../../manifest'
import {
getNVueCompiler,
getNVueFlexDirection,
getNVueStyleCompiler,
} from '../manifest'
import { getLocales } from './locale'
interface AppUniConfig {
pages: string[]
......@@ -60,7 +61,7 @@ export function normalizeAppUniConfig(
entryPagePath: pagesJson.pages[0].path,
networkTimeout: normalizeNetworkTimeout(manifestJson.networkTimeout),
tabBar: pagesJson.tabBar,
locales: getLocales(process.env.UNI_INPUT_DIR),
locales: initLocales(path.join(process.env.UNI_INPUT_DIR, 'locale')),
}
// TODO 待支持分包
return JSON.stringify(config)
......
......@@ -13,8 +13,8 @@ export const M = {
'dev.watching.end.files': 'DONE Build complete. FILES:{files}',
'stat.warn.appid':
'当前应用未配置 appid,无法使用 uni 统计,详情参考:https://ask.dcloud.net.cn/article/36303',
'i18n.fallbackLocale.missing':
'i18n.fallbackLocale.default':
'当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{locale}',
'i18n.fallbackLocale.unmatch':
'i18n.fallbackLocale.missing':
'当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件',
}
export * from './useI18n'
export * from './messages'
export * from './pageMeta'
export * from './utils'
import { once } from '@dcloudio/uni-shared'
import { defineI18nProperty } from '.'
import { defineI18nProperties } from './useI18n'
......@@ -31,3 +32,12 @@ export function initPullToRefreshI18n(
]) as [boolean, boolean, boolean]
}
}
export function initTabBarI18n(tabBar: UniApp.TabBarOptions) {
if (isEnableLocale()) {
tabBar.list.forEach((item) => {
defineI18nProperty(item, ['text'])
})
}
return tabBar
}
......@@ -141,6 +141,14 @@ function initNavigationBarI18n(navigationBar) {
]);
}
}
function initTabBarI18n(tabBar2) {
if (isEnableLocale()) {
tabBar2.list.forEach((item) => {
defineI18nProperty(item, ["text"]);
});
}
return tabBar2;
}
const E = function() {
};
E.prototype = {
......@@ -6697,7 +6705,7 @@ PolySymbol(process.env.NODE_ENV !== "production" ? "layout" : "l");
let tabBar;
function useTabBar() {
if (!tabBar) {
tabBar = __uniConfig.tabBar && vue.reactive(__uniConfig.tabBar);
tabBar = __uniConfig.tabBar && vue.reactive(initTabBarI18n(__uniConfig.tabBar));
}
return tabBar;
}
......
......@@ -234,6 +234,14 @@ function initNavigationBarI18n(navigationBar) {
]);
}
}
function initTabBarI18n(tabBar2) {
if (isEnableLocale()) {
tabBar2.list.forEach((item) => {
defineI18nProperty(item, ["text"]);
});
}
return tabBar2;
}
const E = function() {
};
E.prototype = {
......@@ -13414,7 +13422,7 @@ PolySymbol(process.env.NODE_ENV !== "production" ? "layout" : "l");
let tabBar;
function useTabBar() {
if (!tabBar) {
tabBar = __uniConfig.tabBar && reactive(__uniConfig.tabBar);
tabBar = __uniConfig.tabBar && reactive(initTabBarI18n(__uniConfig.tabBar));
}
return tabBar;
}
......
import { reactive } from 'vue'
import { initTabBarI18n } from '@dcloudio/uni-core'
let tabBar: UniApp.TabBarOptions | undefined
export function useTabBar() {
if (!tabBar) {
tabBar =
__uniConfig.tabBar && reactive<UniApp.TabBarOptions>(__uniConfig.tabBar)
__uniConfig.tabBar &&
reactive<UniApp.TabBarOptions>(initTabBarI18n(__uniConfig.tabBar))
}
return tabBar
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册