Compare commits
1 Commits
a5d4c05392
...
a91c379096
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a91c379096 |
@@ -4,7 +4,7 @@
|
|||||||
// 语言切换:嵌入时父项目经 :locale prop 传入当前语言,watch 同步到本实例;
|
// 语言切换:嵌入时父项目经 :locale prop 传入当前语言,watch 同步到本实例;
|
||||||
// 独立运行时由本组件内的语言开关 + loadLocaleAsync 自管。
|
// 独立运行时由本组件内的语言开关 + loadLocaleAsync 自管。
|
||||||
import { ref, watch, defineAsyncComponent } from 'vue'
|
import { ref, watch, defineAsyncComponent } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from './composables/useLocale.js'
|
||||||
import i18n, { loadLocaleAsync } from './i18n/index.js'
|
import i18n, { loadLocaleAsync } from './i18n/index.js'
|
||||||
import HeroSection from './components/HeroSection.vue'
|
import HeroSection from './components/HeroSection.vue'
|
||||||
import ScreenshotCarousel from './components/ScreenshotCarousel.vue'
|
import ScreenshotCarousel from './components/ScreenshotCarousel.vue'
|
||||||
@@ -28,7 +28,7 @@ watch(
|
|||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
|
|
||||||
const tabs = subTabs
|
const tabs = subTabs
|
||||||
const activeTab = ref(defaultSubTab)
|
const activeTab = ref(defaultSubTab)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../composables/useLocale.js'
|
||||||
import { assets } from '../config.js'
|
import { assets } from '../config.js'
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../composables/useLocale.js'
|
||||||
import Tag from './ui/Tag.vue'
|
import Tag from './ui/Tag.vue'
|
||||||
import { heroMeta } from '../config.js'
|
import { heroMeta } from '../config.js'
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../composables/useLocale.js'
|
||||||
import VersionTimeline from './VersionTimeline.vue'
|
import VersionTimeline from './VersionTimeline.vue'
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../composables/useLocale.js'
|
||||||
import { leaderboard } from '../config.js'
|
import { leaderboard } from '../config.js'
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
|
|
||||||
const rows = ref([])
|
const rows = ref([])
|
||||||
const state = ref('loading') // loading | ok | error
|
const state = ref('loading') // loading | ok | error
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onUnmounted } from 'vue'
|
import { ref, onMounted, onUnmounted } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../composables/useLocale.js'
|
||||||
import { assets } from '../config.js'
|
import { assets } from '../config.js'
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
const images = assets.screenshots
|
const images = assets.screenshots
|
||||||
const current = ref(0)
|
const current = ref(0)
|
||||||
let timer = null
|
let timer = null
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../composables/useLocale.js'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
tabs: { type: Array, required: true }, // [{ id, labelKey }]
|
tabs: { type: Array, required: true }, // [{ id, labelKey }]
|
||||||
@@ -7,7 +7,7 @@ const props = defineProps({
|
|||||||
})
|
})
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../composables/useLocale.js'
|
||||||
import TeamCard from './TeamCard.vue'
|
import TeamCard from './TeamCard.vue'
|
||||||
import Leaderboard from './Leaderboard.vue'
|
import Leaderboard from './Leaderboard.vue'
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../composables/useLocale.js'
|
||||||
import { versions, tracks } from '../data/versions.js'
|
import { versions, tracks } from '../data/versions.js'
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
|
|
||||||
// 按 tracks 数组顺序分组(3D 最终形态在前);同一线内按 order 排序
|
// 按 tracks 数组顺序分组(3D 最终形态在前);同一线内按 order 排序
|
||||||
const grouped = computed(() => {
|
const grouped = computed(() => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useLocale } from '../../composables/useLocale.js'
|
||||||
|
|
||||||
// 可复用页面外壳 -- 统一页面的容器宽度、垂直节奏与标题。
|
// 可复用页面外壳 -- 统一页面的容器宽度、垂直节奏与标题。
|
||||||
// Props:
|
// Props:
|
||||||
@@ -13,7 +13,7 @@ const props = defineProps({
|
|||||||
padded: { type: Boolean, default: true }
|
padded: { type: Boolean, default: true }
|
||||||
})
|
})
|
||||||
|
|
||||||
const { t } = useI18n({ useScope: 'global' })
|
const { t } = useLocale()
|
||||||
const title = computed(() => (props.titleKey ? t(props.titleKey) : ''))
|
const title = computed(() => (props.titleKey ? t(props.titleKey) : ''))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
14
src/composables/useLocale.js
Normal file
14
src/composables/useLocale.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { computed } from 'vue'
|
||||||
|
import i18n from '../i18n/index.js'
|
||||||
|
|
||||||
|
// ★ 子项目自有的语言辅助 composable。
|
||||||
|
// 关键:直接读模块级 i18n 实例的 global composer,而非 useI18n() 注入。
|
||||||
|
// 原因:useI18n({ useScope: 'global' }) 解析的是「当前运行 app 已安装的全局 i18n」,
|
||||||
|
// 嵌入 mainPage 时那是父项目的实例(不含本子项目 mobileGame.* 文案)-> 文案回退成 key。
|
||||||
|
// 改为直接引用本子项目实例的 .global,无论是否 app.use() 都拿到本子项目的 t。
|
||||||
|
export function useLocale() {
|
||||||
|
const { t, locale } = i18n.global
|
||||||
|
const isZh = computed(() => locale.value === 'zh-CN')
|
||||||
|
const pick = (obj) => (isZh.value ? obj.zh : obj.en)
|
||||||
|
return { t, locale, isZh, pick }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user