Skip to content

Commit

Permalink
fix: detect langDir absolute path and refer to docs (#1921)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Mar 10, 2023
1 parent 4aeeeec commit 2960bb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion docs/content/3.options/3.lazy.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2960bb4

Please sign in to comment.