Repository navigation
Description
Which @angular/* package(s) are relevant/related to the feature request?
localize
Description:
The recent deprecation of the baseHref field in the i18n.sourceLocale configuration causes significant issues for projects that rely on a shared base URL for multiple localized builds.
While the subPath feature is a welcome addition for structuring locale builds, it is limiting for developers who:
- Want locale-specific builds in subdirectories (
subPath) without altering the<base>tag inindex.html. - Depend on a static
baseHreffor all builds due to server or application constraints.
Current Behavior:
With subPath enabled:
Angular modifies the <base href> tag in index.html to include the locale-specific subpath (e.g., /zh-hans/), and there is no built-in way to override this behavior.
Without baseHref:
Developers are forced to implement error-prone and maintenance-heavy post-build scripts to reset the <base> tag to their desired value.
Expected Behavior:
Projects with subPath configured should still have the option to:
Use baseHref as a static value across all locale builds.
Separate the functionality of subPath (output directory) from the <base> tag in index.html.
Proposed solution
Instead of fully deprecating baseHref, it could coexist with subPath to give developers more flexibility. Suggested behavior:
-
baseHreftakes precedence if defined. This ensures that:- The
<base>tag inindex.htmlusesbaseHreffor all builds. - subPath is only used for structuring the output directory, not modifying
index.html.
- The
-
If
baseHrefis not specified, the currentsubPathbehavior remains unchanged.
Alternatives considered
Developers are forced to implement error-prone and maintenance-heavy post-build scripts to reset the tag to their desired value.
Activity
alan-agius4 commentedon Jan 18, 2025
Can you please share your i18n configure?
jusfeel commentedon Jan 19, 2025
zip-fa commentedon Jan 19, 2025
He is probably talking about two different domains, eg:
https://my-cool-app.com
https://zh-audience-app.cn
Where single app is served and / url is different locale.
But this only possible when:
So i am pretty unsure on this issue. Probably moving i18n to configuration will be more suitable
anisabboud commentedon Jan 19, 2025
I'm facing a similar issue/dilemma trying to transition to
subPath.Consider the following
angular.jsonconfiguration:This configuration provides the flexibility to create different multi-language builds for different customers. E.g.,
I know this might be pushing the limits of what's possible in the current configuration, but since your goal is to improve the configuration, it would be great if the case above could be handled/supported (or at least not be rendered impossible).
With the new update (deprecating
baseHrefin favor ofsubPath),ng serveno longer works:Error: Invalid i18n configuration: Locales 'en' and 'de-base' cannot have the same subPath: ''.Suggestion
Perhaps
subPathshould be configured/overridden under the"localize"array, and not under"i18n" > "locales"?"localize"would take an array of locales (just like now), and the first locale in the array would be considered the default (baseHref "/") while the rest of the locales in the array would have their subPath set to the locale code by default, unless specifically overridden.In such case, the configuration above could be simplified as follows:
This would also solve a minor issue we currently have with the previous setup, where we define another locale (e.g.,
it-base) in addition to the standard locale (e.g.,it) to support both cases of Italian as the primary language (baseHref "/") as well as Italian as a secondary language (baseHref "/it/"): When weinject(LOCALE_ID), it injects "it-base" instead of "it", and similarly in the HTML:<html lang="it-base">. This is behaving "OK", but it's not ideal.The suggested configuration (moving
"subPath"in the schema from"locales"to"localize") would solve this as well.alan-agius4 commentedon Jan 20, 2025
@jusfeel, just to confirm—you're not building both locales that share the same
baseHref/subPathsimultaneously, correct?fix(@angular/build): only issue invalid i18n config error for duplica…
fix(@angular/build): only issue invalid i18n config error for duplica…
jusfeel commentedon Jan 21, 2025
I build them into 2 subfolders with the same base in the index.html
This is the config:
The final build under
dist/browser/is:en,zh-hans.index.htmlunder both folder are the same:build.options.baseHref.<base href="/da/">fix(@angular/build): replace deprecation of `i18n.baseHref`
fix(@angular/build): replace deprecation of `i18n.baseHref` with a wa…
fix(@angular/build): replace deprecation of `i18n.baseHref` with a wa…
fix(@angular/build): replace deprecation of `i18n.baseHref` with a wa…
angular-automatic-lock-bot commentedon Feb 21, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.