i18n icon indicating copy to clipboard operation
i18n copied to clipboard

[BUG?]: Locale resolver scans `srcDir` instead of `rootDir`

Open Gerbuuun opened this issue 1 year ago • 5 comments

In Nuxt 4 the srcDir will be app by default instead of being the same as the rootDir. I want to put my lang directory outside of the app directory because I also use translations server side.

In the module setup it will scan the srcDir for the translation files but they are located outside of it. https://github.com/nuxt-modules/i18n/blob/cddb8b31825405f08f569f882b6d80284c263ca7/src/module.ts#L184-L188

(The experimental.localeDetector, in contrast, does scan the rootDir) https://github.com/nuxt-modules/i18n/blob/cddb8b31825405f08f569f882b6d80284c263ca7/src/nitro.ts#L138

I tested the module with only changing the nuxt.options.srcDir to nuxt.options.rootDir and it works fine. I hope this is the easy fix I think it is.

cc @danielroe

Gerbuuun avatar Jun 20 '24 00:06 Gerbuuun

Just realized I can use a relative path in the config.

i18n: {
  langDir: '../lang',
}

A point on consistency could still be made though.

Gerbuuun avatar Jun 20 '24 13:06 Gerbuuun

Thank you for your reporting! We are now going to work on nuxt-i18n v9. At that time we will also test it with nuxt4. Please wait!

kazupon avatar Jun 24 '24 02:06 kazupon

This is also an issue when using local modules with Nuxt4 directory structure, I haven't found a way around this yet tbh:

ERROR  Pre-transform error: Failed to resolve import "../app/modules/mylocalmodule/src/runtime/lang/de-AT.json" from ".nuxt/i18n.options.mjs". Does the file exist? (x7)

It tries to look up the module under /app/modules which should actually be /modules.

I'd even argue that this is already broken vor v3 for people that change their srcDir manually to be different from rootDir. I just seems to happen that nobody actually does this in practice right now.

bernhardberger avatar Aug 05 '24 13:08 bernhardberger

@bernhardberger Could you open an issue with a reproduction on https://github.com/nuxt/nuxt ? 🙏

danielroe avatar Aug 05 '24 15:08 danielroe

@Gerbuuun In v9 we will have a new default directory structure to be more consistent with Nuxt 4, we've just released https://github.com/nuxt-modules/i18n/releases/tag/v8.4.0 which allows you to opt into this feature. I18n files will be resolved from this directory in the root of a project, more details on this on the documentation page.

Let me know if you have any questions, hopefully this resolves your issue 😄

BobbieGoede avatar Aug 15 '24 19:08 BobbieGoede

Closing this as this should be working as documented/expected in v9 and higher.

BobbieGoede avatar Mar 20 '25 21:03 BobbieGoede