Skip to content

Commit 80a5340

Browse files
authored
fix: internationalization-related modifications, temporarily hide the entry point (#3597)
* fix: add entrance in western portuguese * fix: revise inspection comments * fix: optimized code * fix: revise inspection comments
1 parent eb2ce65 commit 80a5340

File tree

20 files changed

+221
-39
lines changed

20 files changed

+221
-39
lines changed

examples/sites/src/components/demo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const showPreview = inject('showPreview')
123123
const state = reactive({
124124
tabValue: 'tab0',
125125
cmpId: router.currentRoute.value.params.cmpId,
126-
langKey: getWord('zh-CN', 'en-US'),
126+
langKey: getWord('zh-CN', 'en-US', 'es-LA', 'pt-BR'),
127127
copyTip: i18nByKey('copyCode'),
128128
copyIcon: 'i-ti-copy'
129129
})

examples/sites/src/const.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ export const LANG_KEY = '_lang'
55
// localStorage中保存语言的value
66
export const ZH_CN_LANG = 'zhCN'
77
export const EN_US_LANG = 'enUS'
8+
export const ES_LA_LANG = 'esLA'
9+
export const PT_BR_LANG = 'ptBR'
10+
811
// 语言key值对应的路由
912
export const LANG_PATH_MAP = {
1013
[ZH_CN_LANG]: 'zh-CN',
11-
[EN_US_LANG]: 'en-US'
14+
[EN_US_LANG]: 'en-US',
15+
[ES_LA_LANG]: 'es-LA',
16+
[PT_BR_LANG]: 'pt-BR'
1217
}
1318

1419
export const CURRENT_THEME_KEY = 'tiny-current-theme'

examples/sites/src/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"zh-cn": "Chinese",
33
"en-us": "English",
4+
"es-la": "Spanish",
5+
"pt-br": "Portuguese",
46
"localeType": "Language Selection",
57
"dark": "Dark",
68
"light": "Light",

examples/sites/src/i18n/es.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"zh-cn": "Chinese",
3+
"en-us": "English",
4+
"es-la": "Spanish",
5+
"pt-br": "Portuguese",
6+
"localeType": "Language Selection",
7+
"dark": "Dark",
8+
"light": "Light",
9+
"searchPlaceholder": "Search",
10+
"home": "Home",
11+
"doc": "Docs",
12+
"component": "Components",
13+
"common": "Common",
14+
"apiPreference": "Framework",
15+
"apiTiny": "Vue",
16+
"yan-shi": "Demo",
17+
"demos": "Demos",
18+
"api": "API",
19+
"name": "Name",
20+
"propType": "Type",
21+
"defValue": "Default",
22+
"typeValue": "Option Value",
23+
"desc": "Description",
24+
"showCode": "Show Code",
25+
"hideCode": "Hide Code",
26+
"copyCode": "Copy Code",
27+
"doc-owner": "Owner",
28+
"copyCodeOk": "Copy Success",
29+
"frameAngular": "Angular",
30+
"playground": "Open Playground",
31+
"changeLanguage": "Change Language",
32+
"changeTheme": "Change Components Theme",
33+
"changeApiType": "Change Api Type",
34+
"backTop": "Back To Top",
35+
"overview": "Components Overview",
36+
"overviewDesc": "TinyVue provides a wealth of basic UI components for web applications, and we will continue to explore the best UI practices for enterprise-level applications. Welcome to try TinyVue.",
37+
"overviewDescPlus": "TinyVuePlus is a component library for Cloud business scenarios based on TinyVue, following the new design specifications of Cloud CloudDesign and utilizing Vite+Vue3+TypeScript technology stack.",
38+
"searchComponents": "search components",
39+
"apiType": "Components demos code style",
40+
"apiStyleOptions": "Options",
41+
"apiStyleComposition": "Composition",
42+
"demoMode": "Demo display mode",
43+
"demoModeSingle": "Single",
44+
"demoModeMultiple": "Multiple",
45+
"contributor": "Contributors",
46+
"noData": "No Data"
47+
}

examples/sites/src/i18n/index.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@ import { initI18n, t } from '@opentiny/vue-locale'
33
import { $local } from '../tools'
44
import zh from './zh.json'
55
import en from './en.json'
6+
import esLA from './es.json'
7+
import ptBR from './pt.json'
8+
9+
const messages = { enUS: { ...en }, zhCN: { ...zh }, esLA: { ...esLA }, ptBR: { ...ptBR } }
10+
11+
const langMap = new Map([
12+
['zhCN', 'zhCN'],
13+
['enUS', 'enUS'],
14+
['esLA', 'esLA'],
15+
['ptBR', 'ptBR']
16+
])
17+
18+
$local._lang = langMap.get($local._lang) || 'zhCN'
619

7-
const messages = { enUS: { ...en }, zhCN: { ...zh } }
8-
// $local._lang = $local._lang !== 'zhCN' && $local._lang !== 'enUS' ? 'zhCN' : $local._lang
9-
$local._lang = 'zhCN'
1020
const customCreateI18n = ({ locale, messages }) =>
1121
createI18n({
1222
locale, // set locale
1323
// legacy: false, // 如果要支持compositionAPI,此项必须设置为false。
1424
fallbackLocale: 'zhCN', // set fallback locale
1525
messages // set locale messages
1626
})
17-
1827
const i18n = initI18n({
1928
createI18n: customCreateI18n,
2029
i18n: {
@@ -23,7 +32,17 @@ const i18n = initI18n({
2332
messages
2433
})
2534
const i18nByKey = i18n.global.t
26-
const getWord = (cn, en) => (i18n.global.locale === 'zhCN' ? cn : en)
35+
const getWord = (cn, en, es, pt) => {
36+
const localeMap = new Map([
37+
['zhCN', cn], // 简体中文
38+
['enUS', en], // 英语
39+
['esLA', es], // 西班牙语
40+
['ptBR', pt] // 葡萄牙语
41+
])
42+
const currentLocale = i18n.global.locale
43+
44+
return localeMap.get(currentLocale) ?? cn
45+
}
2746

2847
export { i18n, i18nByKey, getWord }
2948

examples/sites/src/i18n/pt.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"zh-cn": "Chinese",
3+
"en-us": "English",
4+
"es-la": "Spanish",
5+
"pt-br": "Portuguese",
6+
"localeType": "Language Selection",
7+
"dark": "Dark",
8+
"light": "Light",
9+
"searchPlaceholder": "Search",
10+
"home": "Home",
11+
"doc": "Docs",
12+
"component": "Components",
13+
"common": "Common",
14+
"apiPreference": "Framework",
15+
"apiTiny": "Vue",
16+
"yan-shi": "Demo",
17+
"demos": "Demos",
18+
"api": "API",
19+
"name": "Name",
20+
"propType": "Type",
21+
"defValue": "Default",
22+
"typeValue": "Option Value",
23+
"desc": "Description",
24+
"showCode": "Show Code",
25+
"hideCode": "Hide Code",
26+
"copyCode": "Copy Code",
27+
"doc-owner": "Owner",
28+
"copyCodeOk": "Copy Success",
29+
"frameAngular": "Angular",
30+
"playground": "Open Playground",
31+
"changeLanguage": "Change Language",
32+
"changeTheme": "Change Components Theme",
33+
"changeApiType": "Change Api Type",
34+
"backTop": "Back To Top",
35+
"overview": "Components Overview",
36+
"overviewDesc": "TinyVue provides a wealth of basic UI components for web applications, and we will continue to explore the best UI practices for enterprise-level applications. Welcome to try TinyVue.",
37+
"overviewDescPlus": "TinyVuePlus is a component library for Cloud business scenarios based on TinyVue, following the new design specifications of Cloud CloudDesign and utilizing Vite+Vue3+TypeScript technology stack.",
38+
"searchComponents": "search components",
39+
"apiType": "Components demos code style",
40+
"apiStyleOptions": "Options",
41+
"apiStyleComposition": "Composition",
42+
"demoMode": "Demo display mode",
43+
"demoModeSingle": "Single",
44+
"demoModeMultiple": "Multiple",
45+
"contributor": "Contributors",
46+
"noData": "No Data"
47+
}

examples/sites/src/i18n/zh.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"zh-cn": "中文",
33
"en-us": "英文",
4+
"es-la": "西班牙语",
5+
"pt-br": "葡萄牙语",
46
"localeType": "语言选择",
57
"dark": "深色",
68
"light": "浅色",

examples/sites/src/main.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { i18n } from './i18n/index'
2020
import { router } from './router'
2121
import App from './App.vue'
2222
import { appData } from './tools'
23-
import { ZH_CN_LANG, EN_US_LANG, LANG_PATH_MAP } from './const'
23+
import { ZH_CN_LANG, EN_US_LANG, LANG_PATH_MAP, ES_LA_LANG, PT_BR_LANG } from './const'
2424
import demoConfig from '@demos/config.js'
2525

2626
import hljs from 'highlight.js/lib/core'
@@ -31,6 +31,7 @@ import tsPath from 'highlight.js/lib/languages/typescript'
3131
import docsearch from '@docsearch/js'
3232
import '@docsearch/css'
3333
import { doSearchEverySite } from './tools/docsearch'
34+
import { getLocaleMode } from './tools/utils.js'
3435
import '@opentiny/vue-theme/dark-theme-index.css'
3536

3637
const envTarget = import.meta.env.VITE_BUILD_TARGET || 'open'
@@ -65,12 +66,19 @@ setTimeout(() => {
6566

6667
const zhPath = LANG_PATH_MAP[ZH_CN_LANG]
6768
const enPath = LANG_PATH_MAP[EN_US_LANG]
69+
const esPath = LANG_PATH_MAP[ES_LA_LANG]
70+
const ptPath = LANG_PATH_MAP[PT_BR_LANG]
6871
const isZhCn = location.href.includes(`/${zhPath}`)
6972
const isEnUs = location.href.includes(`/${enPath}`)
70-
const notMatchLang = (isZhCn && appData.lang !== ZH_CN_LANG) || (isEnUs && appData.lang !== EN_US_LANG)
73+
const isEsLa = location.href.includes(`/${esPath}`)
74+
const isPtBr = location.href.includes(`/${ptPath}`)
75+
const notMatchLang =
76+
(isZhCn && appData.lang !== ZH_CN_LANG) ||
77+
(isEnUs && appData.lang !== EN_US_LANG) ||
78+
(isEsLa && appData.lang !== ES_LA_LANG) ||
79+
(isPtBr && appData.lang !== PT_BR_LANG)
7180
if (notMatchLang) {
72-
// appData.lang = isEnUs ? EN_US_LANG : ZH_CN_LANG 官网先屏蔽英文内容
73-
appData.lang = isEnUs ? ZH_CN_LANG : ZH_CN_LANG
81+
appData.lang = getLocaleMode()
7482
i18n.global.locale = appData.lang
7583
}
7684

examples/sites/src/router.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ const Overview = () => import('@/views/overview.vue')
99
const Features = () => import('@/views/features.vue')
1010

1111
const context = import.meta.env.VITE_CONTEXT
12-
1312
let routes = [
1413
// 组件总览
1514
{
16-
path: `${context}:all?/zh-CN/:theme/overview`,
15+
path: `${context}:all?/${LANG_PATH_MAP[appData.lang] || 'zh-CN'}/:theme/overview`,
1716
component: Layout,
1817
name: 'overview',
1918
children: [{ name: 'Overview', path: '', component: Overview, meta: { title: '组件总览 | TinyVue' } }]
@@ -27,7 +26,7 @@ let routes = [
2726
},
2827
// 组件
2928
{
30-
path: `${context}:all?/zh-CN/:theme/components/:cmpId`,
29+
path: `${context}:all?/${LANG_PATH_MAP[appData.lang] || 'zh-CN'}/:theme/components/:cmpId`,
3130
component: Layout,
3231
name: 'components',
3332
children: [{ name: 'Components', path: '', component: Components }]
@@ -43,7 +42,7 @@ let routes = [
4342
{
4443
path: '/:pathMatch(.*)*',
4544
redirect: () => {
46-
const langPath = LANG_PATH_MAP[ZH_CN_LANG]
45+
const langPath = LANG_PATH_MAP[appData.lang] || LANG_PATH_MAP[ZH_CN_LANG]
4746
return { path: `${context}${langPath}/${DEFAULT_THEME}/overview` }
4847
}
4948
}

examples/sites/src/tools/appData.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { reactive, computed } from 'vue'
22
import { useAutoStore } from './storage'
33
import { useMediaQuery } from './useMediaQuery'
4-
import { ZH_CN_LANG, EN_US_LANG, LANG_KEY, LANG_PATH_MAP } from '../const'
4+
import { ZH_CN_LANG, LANG_KEY, LANG_PATH_MAP } from '../const'
55

6-
const zhPath = LANG_PATH_MAP[ZH_CN_LANG]
7-
const enPath = LANG_PATH_MAP[EN_US_LANG]
86
const appData = reactive({
97
lang: useAutoStore('local', LANG_KEY, ZH_CN_LANG),
108
theme: useAutoStore('local', '_theme', 'light'),
@@ -16,9 +14,10 @@ const appFn = {
1614
if (name !== appData.lang) {
1715
let url = location.href
1816
url = location.href.replace(LANG_PATH_MAP[appData.lang], LANG_PATH_MAP[name])
19-
// appData.lang = name 官网先屏蔽英文内容
17+
// appData.lang = name // 官网先屏蔽切换语言,默认中文
2018
appData.lang = ZH_CN_LANG
21-
location.replace(url)
19+
history.replaceState({}, '', url)
20+
location.reload()
2221
}
2322
},
2423
toggleTheme() {

0 commit comments

Comments
 (0)