Repository navigation
Description
Describe the feature
Background
The nuxt-i18n module provides a strategy option with the following values:
no_prefixprefix_except_defaultprefixprefix_and_default
ref: https://i18n.nuxtjs.org/docs/guide
The no_prefix strategy disables the use of locale prefixes (e.g., /en, /ja) in the URL.
Additionally, nuxt-i18n has a feature that automatically detects the locale based on the URL. For example, accessing a URL like /en/* will switch the locale to en.
However, when the no_prefix strategy is used, this automatic locale detection based on the pathname is disabled, as the pathname does not contain locale information.
ref:
Lines 247 to 249 in 25b900a
| } else if (__I18N_STRATEGY__ !== 'no_prefix') { | |
| detected ||= routeLocale | |
| } |
This behavior seems logical given the absence of locale information in the URL. However, it causes issues when building multilingual documentation sites using nuxt/content.
Example Use Case:
Suppose we have the following markdown files for multilingual content:
docs/en/about.mddocs/ja/about.md
In this case, we want to access /en/about and /ja/about to display the corresponding localized content. However, since the locale detection from pathname is disabled with no_prefix, the locale is not correctly detected based on the URL.
As a result, during SSG (Static Site Generation), both /en/about and /ja/about will be generated using the language setting of the build machine, causing incorrect locale assignments.
e.g. https://github.com/odan-sandbox/nuxt-content-and-i18n-no_prefix-example
| http://localhost:3000/en/about | http://localhost:3000/ja/about |
|---|---|
![]() |
![]() |
Proposed Feature: localeDetector Option
Current Behavior Example
To illustrate the current behavior, consider the following scenario:
- Accessing
/en/aboutand/ja/aboutunder theno_prefixstrategy will not trigger locale detection based on the pathname. - As a result, both paths will use the language setting of the build machine during SSG, resulting in both paths potentially being generated in the same language.
Screenshots and repository links demonstrating the current behavior will be provided to further clarify the issue.
To address this issue, I propose adding a new localeDetector option to the module configuration. This option allows specifying the methods for locale detection as follows:
type LocaleDetector = ("pathname" | "domain" | "cookie" | "browser")[];
const localeDetector: LocaleDetector = ["pathname", "domain", "cookie", "browser"];If pathname is specified, the locale will be automatically detected based on the URL pathname.
The default value of localeDetector will vary depending on the strategy value to maintain backward compatibility. For instance, when no_prefix is selected, the default value would be:
localeDetector: ["domain", "cookie", "browser"]Example Configuration for My Use Case:
strategy: "no_prefix",
localeDetector: ["pathname", "cookie", "browser"]This configuration would resolve the issue by enabling locale detection based on pathname while maintaining backward compatibility with existing behavior.
Thank you for considering this feature request. I would be happy to provide further clarifications or contribute to the implementation if needed.
Additional information
- Would you be willing to help implement this feature?
- Could this feature be implemented as a module?
Final checks
- Read the contribution guide (The contribution guideline of nuxt-modules/i18n is compliant with Nuxt too).
- Check existing discussions and issues.


Activity
odanado commentedon May 16, 2025
The detection function specified by
experimental.localeDetectoris only executed for API calls and is not invoked during the rendering of Vue components. Therefore, it does not conflict with the proposedlocaleDetectoroption.ref: https://i18n.nuxtjs.org/docs/guide/server-side-translations
Additionally, since
experimental.localeDetectoris intended for server-side translations, it might be more appropriate to rename it toexperimental.serverLocaleDetectorif the proposedlocaleDetectoroption is adopted.BobbieGoede commentedon May 17, 2025
Thank you for the well thought out feature request 🙏
I have considered changing locale detection to be modular and configurable before, much like the approach you suggest, but other changes took priority at that time and I wasn't sure if there was any demand for it.
The current locale detection is a bit complicated:
I have started work on refactors #3611 and will rework the detection to hopefully work towards a configurable approach.
One request, could you extract the issue (problem/use case) out of this feature request into a separate issue? 🙏 There may be other (temporary or better suited) solutions that could work for your use case.