Closed zakarialounes closed 5 months ago
By adding as many github content sources as defined locales, I was able to get the github content driver working with i18n.
// nuxt.config.ts
import { defaultLocale, locales, localesCode } from './locales.config'
import { sources } from './github-content-sources.config'
export default defineNuxtConfig({
// ...
i18n: {
locales,
lazy: true,
strategy: 'prefix_except_default',
detectBrowserLanguage: false,
langDir: 'lang/',
defaultLocale,
vueI18n: './i18n.config.ts'
},
content: {
defaultLocale,
locales: localesCode,
sources
}
// ...
})
// github-content-sources.config.ts
import { localesCode } from './locales.config'
const is18nForGithubDriverSupported = false
const contentSourceRegistry = {
prefix: '/protocols',
driver: 'github',
repo: 'ezstaking/website-registry',
branch: 'main',
dir: 'build/_content'
}
export const sources = is18nForGithubDriverSupported
? { registry: contentSourceRegistry }
: localesCode.reduce(
(accumulator, locale) => {
return {
...accumulator, [`registry_${locale}`]: {
...contentSourceRegistry,
prefix: '/' + locale + contentSourceRegistry.prefix,
dir: contentSourceRegistry.dir + '/' + locale
}
}
},
{}
)
// locales.config.ts
export const locales = [
{
code: "en",
iso: "en-US",
file: "en-US.json",
name: "English",
dir: "ltr",
},
{
code: 'es',
iso: 'es-ES',
file: 'es-ES.json',
name: 'Español',
dir: "ltr",
},
{
code: 'fr',
iso: "fr-FR",
file: 'fr-FR.json',
name: 'Français',
dir: "ltr",
},
// {
// code: 'ru',
// iso: "ru-RU",
// file: 'next/ru-RU.json',
// name: 'Русский',
// dir: "ltr",
// },
]
export const localesCode = locales.map(locale => locale.code)
export const defaultLocale = "en"
Environment
Darwin
v20.8.1
3.11.2
3.11.1
2.9.6
npm@10.1.0
-
ssr
,devtools
,runtimeConfig
,ignore
,app
,css
,postcss
,plugins
,components
,modules
,build
,eslint
,features
,vite
,i18n
,vuetify
,googleFonts
,nuxt-compress
,content
,robots
,site
,sitemap
,gtag
@nuxt/image@1.7.0
,@nuxtjs/device@3.1.1
,@nuxtjs/google-fonts@3.2.0
,vuetify-nuxt-module@0.13.5
,@pinia/nuxt@0.5.1
,@nuxt/content@2.12.1
,@nuxtjs/i18n@8.2.0
,@nuxtjs/robots@3.0.0
,@nuxtjs/sitemap@5.2.0
,nuxt-gtag@2.0.6
-
Reproduction
Describe the bug
Using GitHub as a source driver do not allow me to take advantage of the i18n as provided for the default content source.
No problem for the default content source with the same files and structure.
Content from GitHub source is identified as English, regardless of the parent directory (en, es, fr).
nuxt.config.ts
i18n.config.ts
GitHub content directory
Default content directory
Retrieved articles for GitHub content directory with locale = 'en' ❌ NOK
Retrieved articles for default content directory with locale = 'en' ✅ OK
Additional context
No response
Logs
No response