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

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

Open
Gerbuuun opened this issue Jun 20, 2024 · 5 comments
Open

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

Gerbuuun opened this issue Jun 20, 2024 · 5 comments

Comments

@Gerbuuun
Copy link

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.

i18n/src/module.ts

Lines 184 to 188 in cddb8b3

const localeInfo = await resolveLocales(
resolve(nuxt.options.srcDir),
normalizedLocales,
relative(nuxt.options.buildDir, nuxt.options.srcDir)
)

(The experimental.localeDetector, in contrast, does scan the rootDir)

const pathTo = resolve(serverI18nLayer.config.rootDir, serverI18nLayer.config.i18n!.experimental!.localeDetector!)

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
Copy link
Author

Gerbuuun commented Jun 20, 2024

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

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

A point on consistency could still be made though.

@kazupon
Copy link
Collaborator

kazupon commented Jun 24, 2024

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!

@BobbieGoede BobbieGoede self-assigned this Jul 31, 2024
@BobbieGoede BobbieGoede added the v9 label Jul 31, 2024
@bernhardberger
Copy link

bernhardberger commented Aug 5, 2024

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.

@danielroe
Copy link
Contributor

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

@BobbieGoede
Copy link
Collaborator

@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 BobbieGoede mentioned this issue Sep 16, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants