Skip to content

Commit

Permalink
fix(docs): Fixed a problem with i18n.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyost committed Dec 1, 2024
1 parent c6fef31 commit e85b9e0
Show file tree
Hide file tree
Showing 9 changed files with 5,949 additions and 7,387 deletions.
23 changes: 12 additions & 11 deletions docs/app.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<script setup lang="ts">
if (import.meta.client) {
onMounted(() => {
const i18n = useI18n()
const browserLocale = i18n.getBrowserLocale()
const locales = i18n.locales
const locale = locales.value.find(({ code }) => code === browserLocale)
if (locale) {
i18n.setLocale(locale.code)
}
})
}
import availableLocales from '~/i18n/availableLocales'
onMounted(async () => {
const i18n = useI18n()
const browserLocale = i18n.getBrowserLocale()
const locales = i18n.locales
const locale = locales.value.find(({ code }) => code === browserLocale)
if (locale && locale != availableLocales[0]) {
await i18n.setLocale(availableLocales[0].code)
await i18n.setLocale(locale.code)
}
})
</script>

<template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export default [
{
code: 'en',
file: 'en.ts',
iso: 'en-US',
languages: 'en-US',
},
{
code: 'fr',
file: 'fr.ts',
iso: 'fr-FR',
languages: 'fr-FR',
},
]
8 changes: 8 additions & 0 deletions docs/i18n/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default defineI18nConfig(() => {
return {
legacy: false,
locale: 'en',
fallbackLocale: 'en',
ssr: true,
}
})
File renamed without changes.
File renamed without changes.
6 changes: 1 addition & 5 deletions docs/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<script setup lang="ts">
const i18nHead = useLocaleHead({
addSeoAttributes: {
canonicalQueries: ['foo'],
},
})
const i18nHead = useLocaleHead()
useHead({
htmlAttrs: {
lang: i18nHead.value.htmlAttrs!.lang,
Expand Down
75 changes: 42 additions & 33 deletions docs/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import StylelintPlugin from 'vite-plugin-stylelint'
import eslintPlugin from '@nabla/vite-plugin-eslint'

import { siteMeta } from './site'
import availableLocales from './locales/availableLocales'
import availableLocales from './i18n/availableLocales'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-07-01',
modules: [
'@nuxt/eslint',
'nuxt-cname-generator',
'@nuxtjs/i18n',
'@nuxt/icon',
'nuxt-link-checker',
'@nuxtjs/sitemap',
'@nuxtjs/robots',
'@bootstrap-vue-next/nuxt',
],
devtools: { enabled: true },

app: {
Expand All @@ -24,33 +33,13 @@ export default defineNuxtConfig({
'~/assets/app.scss',
],

i18n: {
baseUrl: siteMeta.url,
locales: availableLocales,
langDir: 'locales',
defaultLocale: 'en',
strategy: 'no_prefix',
compilation: {
escapeHtml: false,
strictMessage: false,
},
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'language',
redirectOn: 'root',
},
site: {
url: siteMeta.url,
name: siteMeta.name,
trailingSlash: true,
},

modules: [
'@nuxt/eslint',
'nuxt-cname-generator',
'@nuxtjs/i18n',
'@nuxt/icon',
'nuxt-link-checker',
'@nuxtjs/sitemap',
'@nuxtjs/robots',
'@bootstrap-vue-next/nuxt',
],
compatibilityDate: '2024-07-01',

nitro: {
prerender: {
Expand All @@ -65,12 +54,6 @@ export default defineNuxtConfig({
],
},

site: {
url: siteMeta.url,
name: siteMeta.name,
trailingSlash: true,
},

cname: {
host: siteMeta.url,
},
Expand All @@ -80,4 +63,30 @@ export default defineNuxtConfig({
stylistic: true,
},
},

i18n: {
vueI18n: 'i18n.config.ts',
baseUrl: siteMeta.url,
locales: availableLocales,
langDir: 'locales',
defaultLocale: 'en',
strategy: 'no_prefix',
compilation: {
escapeHtml: false,
strictMessage: false,
},
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'language',
redirectOn: 'root',
},
},

linkChecker: {
failOnError: false,
skipInspections: [
'link-text',
'no-uppercase-chars',
],
},
})
Loading

0 comments on commit e85b9e0

Please sign in to comment.