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

fix: detect langDir absolute path and refer to docs #1921

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/content/3.options/3.lazy.md
Expand Up @@ -36,4 +36,10 @@ Whether the translation messages for the current locale should be injected into
- type: `string` or `null`
- default: `null`

Directory that contains translation files to load. Can be used with or without lazy-loading (the `lazy` option). Use Webpack paths like `~/locales/` (with trailing slash).
A relative path to a directory containing translation files to load. Can be used with or without lazy-loading (the `lazy` option).

The path is resolved relative to the project `srcDir` (project root by default).

::alert{type="warning"}
Absolute paths will fail in production (eg. `/locales` should be changed into either `locales` or `./locales`)
::
9 changes: 8 additions & 1 deletion src/module.ts
@@ -1,7 +1,7 @@
import createDebug from 'debug'
import { isBoolean, isObject, isString } from '@intlify/shared'
import { defineNuxtModule, isNuxt2, isNuxt3, getNuxtVersion, addPlugin, addTemplate, addImports } from '@nuxt/kit'
import { resolve, relative } from 'pathe'
import { resolve, relative, isAbsolute } from 'pathe'
import { setupAlias, resolveVueI18nAlias } from './alias'
import { setupPages } from './pages'
import { extendMessages } from './messages'
Expand Down Expand Up @@ -64,6 +64,13 @@ export default defineNuxtModule<NuxtI18nOptions>({
* resolve lang directory
*/

if (isString(options.langDir) && isAbsolute(options.langDir)) {
console.warn(
formatMessage(
`\`langdir\` is set to an absolute path (${options.langDir}) but should be set a path relative to \`srcDir\` (${nuxt.options.srcDir}). Absolute paths will not work in production, see https://v8.i18n.nuxtjs.org/options/lazy#langdir for more details.`
)
)
}
const langPath = isString(options.langDir) ? resolve(nuxt.options.srcDir, options.langDir) : null
debug('langDir path', langPath)

Expand Down