选项
运行时配置
i18n 运行时配置选项。
一些选项可以通过 runtimeConfig
设置,这种方式可让在构建后使用环境变量重写这些选项。
使用方法
如果您想使用环境变量来更改 支持的选项,您需要在 runtimeConfig.public.i18n
中设置这些变量。
nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
// 留下希望使用 `runtimeConfig` 设置的选项
// baseUrl: 'https://example.com',
},
runtimeConfig: {
public: {
i18n: {
baseUrl: 'https://example.com',
locales: {}
// 其他选项 ...
}
}
}
})
您可以在 Nuxt 文档 中阅读有关此功能的更多信息。
runtimeConfig
中仅支持 可序列化值,以这种方式设置的选项可能不支持所有可用类型(例如函数),而使用默认配置通常可以。如果您希望支持其他选项,请打开一个描述您用例的问题,或提交一个 PR 自行添加支持!
支持的选项
模块配置优先,只有在未设置的情况下,才会使用通过 runtimeConfig
设置的选项。
可以使用 runtimeConfig
设置以下选项:
baseUrl
- 键:
NUXT_PUBLIC_I18N_BASE_URL
此运行时配置选项与 baseUrl
模块选项相同。
请注意,
baseUrl
模块选项允许您设置函数,但由于限制,运行时配置不支持。locales
- 属性:
locales[code].domain
- 键:
NUXT_PUBLIC_I18N_LOCALES_{code}_DOMAIN
此运行时配置选项允许重写在 locales
模块选项中设置的域名。