Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to i18n config in nitro context #3032

Open
2 of 4 tasks
warflash opened this issue Jul 16, 2024 · 1 comment
Open
2 of 4 tasks

Access to i18n config in nitro context #3032

warflash opened this issue Jul 16, 2024 · 1 comment

Comments

@warflash
Copy link
Contributor

Describe the feature

It'd be nice to get access to the very basics of the i18n config in nitro.
Just to give a simple example, we're trying to verify a language passed in query params is actually supported by our website. Or load/return data for every possible locale.

There's of course the option to hardcode/copy it, however I think it'd be preferable to be able to pull i18n related configs straight from the source - similar to what useI18n().locales provides.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

@AndersCV
Copy link

AndersCV commented Aug 19, 2024

@warflash I had a similar use case where i needed to validate a local based on a query paramter in a server route. I hacked a workaround that is placing my i18n config in a seperate file and attaching it to my runtimeConfig

// nuxt.config.ts 
export default defineNuxtConfig({
  runtimeConfig: {
    i18n: require('./nuxt.i18n.config'),
  },
})

In order to get typescript working:

// index.d.ts
import { NuxtI18nOptions } from '@nuxtjs/i18n'

declare module '@nuxt/schema' {
  interface RuntimeConfig {
    i18n: NuxtI18nOptions
  }
}

Now no copying is needed - but I also think it would be great if the module could handle this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants