diff --git a/layer/app/app.config.ts b/layer/app/app.config.ts
index c65c06934..8258f67a6 100644
--- a/layer/app/app.config.ts
+++ b/layer/app/app.config.ts
@@ -1,4 +1,7 @@
export default defineAppConfig({
+ docus: {
+ locale: 'en',
+ },
ui: {
colors: {
primary: 'emerald',
diff --git a/layer/app/app.vue b/layer/app/app.vue
index a1003cc2d..679c45bfa 100644
--- a/layer/app/app.vue
+++ b/layer/app/app.vue
@@ -1,13 +1,14 @@
-
+
diff --git a/layer/app/components/LanguageSelect.vue b/layer/app/components/LanguageSelect.vue
index 9f08ea05c..9f1952a62 100644
--- a/layer/app/components/LanguageSelect.vue
+++ b/layer/app/components/LanguageSelect.vue
@@ -28,6 +28,7 @@ function getEmojiFlag(locale: string): string {
uk: 'ua', // Ukrainian -> Ukraine
ur: 'pk', // Urdu -> Pakistan
vi: 'vn', // Vietnamese -> Vietnam
+ es: 'es', // Spanish -> Spain
}
const baseLanguage = locale.split('-')[0]?.toLowerCase() || locale
diff --git a/layer/app/composables/useDocusI18n.ts b/layer/app/composables/useDocusI18n.ts
index 28feec563..d08e3b10a 100644
--- a/layer/app/composables/useDocusI18n.ts
+++ b/layer/app/composables/useDocusI18n.ts
@@ -1,20 +1,22 @@
import type { LocaleObject } from '@nuxtjs/i18n'
-import en from '../../i18n/locales/en.json'
export const useDocusI18n = () => {
const config = useRuntimeConfig().public
const isEnabled = ref(!!config.i18n)
if (!isEnabled.value) {
+ const locale = useNuxtApp().$locale as string
+ const localeMessages = useNuxtApp().$localeMessages as Record
+
return {
isEnabled,
- locale: ref('en'),
+ locale: ref(locale),
locales: [],
localePath: (path: string) => path,
switchLocalePath: () => {},
t: (key: string): string => {
const path = key.split('.')
- return path.reduce((acc: unknown, curr) => (acc as Record)?.[curr], en) as string
+ return path.reduce((acc: unknown, curr) => (acc as Record)?.[curr], localeMessages) as string
},
}
}
diff --git a/layer/app/error.vue b/layer/app/error.vue
index 1ad556376..0b6dd828b 100644
--- a/layer/app/error.vue
+++ b/layer/app/error.vue
@@ -1,6 +1,6 @@
-
+
diff --git a/layer/app/plugins/i18n.ts b/layer/app/plugins/i18n.ts
index e4fc6a6e5..7f026aed8 100644
--- a/layer/app/plugins/i18n.ts
+++ b/layer/app/plugins/i18n.ts
@@ -1,12 +1,34 @@
-export default defineNuxtPlugin(() => {
+import en from '../../i18n/locales/en.json'
+import type { RouteLocationNormalized } from 'vue-router'
+
+export default defineNuxtPlugin(async () => {
const nuxtApp = useNuxtApp()
const i18nConfig = nuxtApp.$config.public.i18n
+
+ // If i18n is not enabled, fetch and provide the configured locale in app config
if (!i18nConfig) {
- return
+ let locale = 'en'
+ let resolvedMessages: Record = en
+
+ const appConfig = useAppConfig()
+ const configuredLocale = appConfig.docus.locale
+ if (configuredLocale !== 'en') {
+ const localeMessages = await import(`../../i18n/locales/${configuredLocale}.json`)
+ if (!localeMessages) {
+ console.warn(`[Docus] Missing locale file for "${configuredLocale}". Falling back to "en".`)
+ }
+ else {
+ locale = configuredLocale
+ resolvedMessages = localeMessages
+ }
+ }
+
+ nuxtApp.provide('locale', locale)
+ nuxtApp.provide('localeMessages', resolvedMessages)
}
- addRouteMiddleware((to) => {
+ addRouteMiddleware((to: RouteLocationNormalized) => {
if (to.path === '/') {
const cookieLocale = useCookie('i18n_redirected').value || i18nConfig.defaultLocale || 'en'
diff --git a/layer/app/types/index.d.ts b/layer/app/types/index.d.ts
index fb5a005b7..4ec153d58 100644
--- a/layer/app/types/index.d.ts
+++ b/layer/app/types/index.d.ts
@@ -1,5 +1,8 @@
declare module 'nuxt/schema' {
interface AppConfig {
+ docus: {
+ locale: string
+ }
seo: {
titleTemplate: string
title: string