Skip to content

Commit

Permalink
feat: add locale path for i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranwv committed Nov 22, 2024
1 parent 2797ed1 commit 13e1fdb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/composables/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
*
* @see https://vueuse.org/core/useDark/
*/
export const isDark = useDark()
export const isDark = useDark({
storageKey: `color-scheme`,
})

/**
* Toggle dark mode
Expand Down
8 changes: 5 additions & 3 deletions app/layouts/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const { toggleLocale } = useLocale()
const route = useRoute()
const localePath = useLocalePath()
const { headerLogo } = storeToRefs(useLayoutStore())
function openGithub() {
Expand All @@ -21,13 +23,13 @@ function openGithub() {
<sup><i>v{{ APP_VERSION }}</i></sup>
</h1>
<div flex="~ wrap gap-2 justify-center">
<TheButton v-if="route.path === '/about'" @click="navigateTo('/')">
<TheButton v-if="route.path === localePath('/about')" @click="navigateTo(localePath('/'))">
{{ t('button.index-page') }}
</TheButton>
<TheButton v-else @click="navigateTo('/about')">
<TheButton v-else @click="navigateTo(localePath('/about'))">
{{ t('button.about-page') }}
</TheButton>
<TheButton @click="navigateTo('/404')">
<TheButton @click="navigateTo(localePath('/404'))">
{{ t('button.404-page') }}
</TheButton>
<TheButton @click="toggleLocale()">
Expand Down
2 changes: 1 addition & 1 deletion app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function fetchData() {
return
loading.value = true
try {
const res = await $fetch<TodoList>('/todos', {
const res = await $fetch<TodoList>('/todo', {
baseURL: runtimeConfig.public.requestBaseUrl,
})
todoList.value = res
Expand Down
3 changes: 3 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export default defineNuxtConfig({
// https://i18n.nuxtjs.org/
i18n: {
defaultLocale: 'en',
// If you don't need the prefix strategy, you can remove the strategy option.
// And you can remove `useLocalePath` in `src` directory.
strategy: 'prefix_and_default',
locales: [
{ code: 'en', file: 'en.json', name: 'English' },
{ code: 'zh', file: 'zh.json', name: '中文' },
Expand Down
File renamed without changes.

0 comments on commit 13e1fdb

Please sign in to comment.