From da175e60842c1130be9fb0f073627f635dba2db5 Mon Sep 17 00:00:00 2001 From: Bobbie Goede Date: Fri, 10 Mar 2023 15:59:14 +0100 Subject: [PATCH] fix: detect langDir absolute path and refer to docs (#1921) --- docs/content/3.options/3.lazy.md | 8 +++++++- src/module.ts | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/content/3.options/3.lazy.md b/docs/content/3.options/3.lazy.md index 80fb1045c..ef91825fb 100644 --- a/docs/content/3.options/3.lazy.md +++ b/docs/content/3.options/3.lazy.md @@ -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`) +:: \ No newline at end of file diff --git a/src/module.ts b/src/module.ts index c965781e8..f6a354f1d 100644 --- a/src/module.ts +++ b/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' @@ -64,6 +64,13 @@ export default defineNuxtModule({ * 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)