Skip to content

Commit

Permalink
chore: use latest i18n v9
Browse files Browse the repository at this point in the history
upstreaming from nimbus-town/nimbus#3
  • Loading branch information
shuuji3 committed Nov 24, 2024
1 parent 63caf91 commit fdc0924
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ We've added some `UnoCSS` utilities styles to help you with that:

## Internationalization

We are using [vue-i18n](https://vue-i18n.intlify.dev/) via [nuxt-i18n](https://v8.i18n.nuxtjs.org/) to handle internationalization.
We are using [vue-i18n](https://vue-i18n.intlify.dev/) via [nuxt-i18n](https://i18n.nuxtjs.org/) to handle internationalization.

You can check the current [translation status](https://docs.elk.zone/docs/guide/contributing#translation-status): more instructions on the table caption.

Expand Down
5 changes: 5 additions & 0 deletions config/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ export const countryLocaleVariants: Record<string, (LocaleObjectData & { country

const locales: LocaleObjectData[] = [
{
// @ts-expect-error en used as placeholder
code: 'en',
file: 'en.json',
name: 'English',
},
({
// @ts-expect-error ar used as placeholder
code: 'ar',
file: 'ar.json',
name: 'العربية',
Expand Down Expand Up @@ -110,6 +112,7 @@ const locales: LocaleObjectData[] = [
},
} satisfies LocaleObjectData),
{
// @ts-expect-error ca used as placeholder
code: 'ca',
file: 'ca.json',
name: 'Català',
Expand Down Expand Up @@ -150,6 +153,7 @@ const locales: LocaleObjectData[] = [
name: 'Nederlands',
},
{
// @ts-expect-error es used as placeholder
code: 'es',
file: 'es.json',
name: 'Español',
Expand Down Expand Up @@ -203,6 +207,7 @@ const locales: LocaleObjectData[] = [
},
},
{
// @ts-expect-error pt used as placeholder
code: 'pt',
file: 'pt.json',
name: 'Português',
Expand Down
7 changes: 5 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,12 @@ export default defineNuxtConfig({
lazy: true,
strategy: 'no_prefix',
detectBrowserLanguage: false,
langDir: 'locales',
langDir: resolve('locales'),
defaultLocale: 'en-US',
vueI18n: './config/i18n.config.ts',
experimental: {
generatedLocaleFilePathFormat: 'relative',
},
vueI18n: resolve('./config/i18n.config.ts'),
},
pwa,
staleDep: {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@nuxt/devtools": "^1.5.2",
"@nuxt/test-utils": "^3.14.3",
"@nuxtjs/color-mode": "^3.4.4",
"@nuxtjs/i18n": "^8.5.3",
"@nuxtjs/i18n": "^9.1.0",
"@pinia/nuxt": "^0.5.4",
"@tiptap/core": "2.2.4",
"@tiptap/extension-bold": "2.2.4",
Expand Down Expand Up @@ -145,9 +145,8 @@
"pnpm": {
"patchedDependencies": {
"pinceau": "patches/pinceau.patch",
"vue-i18n": "patches/vue-i18n.patch",
"nuxt-security": "patches/nuxt-security.patch",
"nuxt": "patches/nuxt.patch"
"@nuxtjs/[email protected]": "patches/@[email protected].patch"
}
},
"resolutions": {
Expand Down
13 changes: 13 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/module.mjs b/dist/module.mjs
index b6def32f8bde5516e6ee0a25f153b01803f55683..897b44120533fdb74b33d9d4dff1d21b910073ca 100644
--- a/dist/module.mjs
+++ b/dist/module.mjs
@@ -1462,7 +1462,7 @@ async function extendBundler({ options: nuxtOptions }, nuxt) {
fullInstall: nuxtOptions.bundle.fullInstall,
onlyLocales: nuxtOptions.bundle.onlyLocales,
dropMessageCompiler: nuxtOptions.bundle.dropMessageCompiler,
- optimizeTranslationDirective: true,
+ optimizeTranslationDirective: false,
strictMessage: nuxtOptions.compilation.strictMessage,
escapeHtml: nuxtOptions.compilation.escapeHtml,
defaultSFCLang: nuxtOptions.customBlocks.defaultSFCLang,
12 changes: 0 additions & 12 deletions patches/nuxt.patch

This file was deleted.

13 changes: 0 additions & 13 deletions patches/vue-i18n.patch

This file was deleted.

6 changes: 4 additions & 2 deletions plugins/setup-i18n.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Locale } from '#i18n'

export default defineNuxtPlugin(async (nuxt) => {
const t = nuxt.vueApp.config.globalProperties.$t
const d = nuxt.vueApp.config.globalProperties.$d
Expand All @@ -11,14 +13,14 @@ export default defineNuxtPlugin(async (nuxt) => {
const i18n = useNuxtApp().$i18n
const { setLocale, locales } = i18n
const userSettings = useUserSettings()
const lang = computed(() => userSettings.value.language)
const lang = computed(() => userSettings.value.language as Locale)

const supportLanguages = unref(locales).map(locale => locale.code)
if (!supportLanguages.includes(lang.value))
userSettings.value.language = getDefaultLanguage(supportLanguages)

if (lang.value !== i18n.locale)
await setLocale(userSettings.value.language)
await setLocale(userSettings.value.language as Locale)

watch([lang, isHydrated], () => {
if (isHydrated.value && lang.value !== i18n.locale)
Expand Down

0 comments on commit fdc0924

Please sign in to comment.