nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.74k stars 483 forks source link

Locale ISO code is required to generate alternate link when using `installModule` #2590

Closed yapengsoft closed 11 months ago

yapengsoft commented 11 months ago

Environment

Reproduction

image image

Describe the bug

Iā€˜m sorry, I can only use pictures I am facing this problem in "rc-6" but it is normal in "rc-5" I want to know what is the reason can you tell me?

Additional context

No response

Logs

No response

github-actions[bot] commented 11 months ago

Would you be able to provide a reproduction? šŸ™

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: šŸ‘‰ [Reproduction starter (v8 and higher)](https://stackblitz.com/fork/github/BobbieGoede/nuxt-i18n-starter/tree/v8) šŸ‘‰ [Reproduction starter (edge)](https://stackblitz.com/fork/github/BobbieGoede/nuxt-i18n-starter/tree/edge) A public GitHub repository is also perfect. šŸ‘Œ Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve)
yapengsoft commented 11 months ago

I apologize. I figured out the issue myself. I made a mistake in my previous message But, I've encountered another issue. I'm not sure how to specify the 'langDir' options when using 'installModule' to install this module. Can you provide guidance on that? image

https://stackblitz.com/edit/nuxt-i18n-queistion

BobbieGoede commented 11 months ago

I wasn't aware of installModule, I will have to look into that sometime.

The reason why it isn't working is because in our logic for layer support we go through all layer configs and resolve the locales relative to each langDir, I'm not sure exactly where the options provided by installModule end up.

Specifically for locales and langdir I recommend using the i18n:registerModule hook, that is made specifically for modules providing translations and/or locales, here is your reproduction but modified to use this hook.

Closing this issue as it has been resolved, if you have any more questions feel free to open a discussion here https://github.com/nuxt-modules/i18n/discussions!

yapengsoft commented 11 months ago

Thank you, it worked But I'm still encountering the error: 'Locale ISO code is required to generate alternate link. because I used 'useLocaleHead'. image https://stackblitz.com/edit/nuxt-i18n-queistion

yapengsoft commented 11 months ago

Why did this issue arise in 'rc-6' when it wasn't a problem in 'rc-5'?

BobbieGoede commented 11 months ago

Why did this issue arise in 'rc-6' when it wasn't a problem in 'rc-5'?

Hmm, did this work without issues in rc.5 specifically using installModule? When installing the module inside Nuxt configuration it works as expected, I changed the reproduction again to demonstrate.

yapengsoft commented 11 months ago

I'm trying to manage the language options through the admin panel as it aligns with my business requirements. So, I attempted to use it within the modules

yapengsoft commented 11 months ago

I confirmed it is working in rc-5

BobbieGoede commented 11 months ago

Could you provide a reproduction of it working using rc.5? I think I may be misunderstanding your issue.

yapengsoft commented 11 months ago

https://stackblitz.com/edit/nuxt-i18n-queistion-ckrqt7?file=nuxt.config.ts,package.json,modules%2Fi18n-resource%2Findex.ts The current usage of 'registerModule' and 'installModule' only works in rc-5; it doesn't work in rc-6 and rc-7 You can try updating '@nuxtjs/i18n' to either rc-6 or rc-7 versions (without modifying any code)

yapengsoft commented 11 months ago

I need this usage because it's crucial for my business. I hope the issue can be resolved in the official v8 release. I would greatly appreciate it. Thank you so much!

BobbieGoede commented 11 months ago

Thank you for providing the reproduction! I think I know what might be the cause of this regression, hopefully I can fix it later today.

yapengsoft commented 11 months ago

Thank you for your hard work

BobbieGoede commented 11 months ago

@yapengsoft The fix has been merged and is now included in the edge channel, I have changed the reproduction to demonstrate here. You may need to remove node_modules and lockfiles before installing!