feat: Implement route-based culture support in localization.#25174
feat: Implement route-based culture support in localization.#25174
Conversation
…r to use CurrentCulture instead of CurrentUICulture
…tenant management pages for URL-based localization
…and enhance menu item URL handling
…oved URL handling and culture prefixing
…estCultureProvider after QueryStringRequestCultureProvider
…turePrefixHelper and adding browser check
…calization handling
|
Images automagically compressed by Calibre's image-actions ✨ Compression reduced images by 79.4%, saving 896.5 KB.
|
|
Images automagically compressed by Calibre's image-actions ✨ Compression reduced images by 71.8%, saving 1.4 MB.
|
…text and update route order for Razor Pages
…ork/abp into feature/url-based-localization
|
Images automagically compressed by Calibre's image-actions ✨ Compression reduced images by 9.7%, saving 40.0 KB.
2 images did not require optimisation. |
There was a problem hiding this comment.
Pull request overview
Implements opt-in route-based culture support (e.g. /tr/...) across ABP’s localization pipeline, including automatic routing, URL generation, menu URL rewriting, and Blazor theme behavior.
Changes:
- Adds
UseRouteBasedCulturetoAbpRequestLocalizationOptionsand wires it into request culture providers + MVC/Razor Pages routing and URL generation. - Introduces menu URL provider infrastructure and culture-prefix providers for MVC/Blazor Server and Blazor WASM.
- Updates built-in Blazor module pages/themes and adds comprehensive tests + documentation for the feature.
Reviewed changes
Copilot reviewed 61 out of 67 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs | Adds Culture route parameter binding. |
| modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor | Adds culture-prefixed @page route. |
| modules/setting-management/src/Volo.Abp.SettingManagement.Blazor/Pages/SettingManagement/SettingManagement.razor.cs | Adds Culture route parameter binding. |
| modules/setting-management/src/Volo.Abp.SettingManagement.Blazor/Pages/SettingManagement/SettingManagement.razor | Adds culture-prefixed @page route. |
| modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs | Adds Culture route parameter binding. |
| modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor | Adds culture-prefixed @page route. |
| modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs | Adds Culture route parameter binding. |
| modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor | Adds culture-prefixed @page route. |
| modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/WebAssemblyRedirectToLogin.razor | Makes login redirect culture-aware in WASM. |
| modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LoginDisplay.razor.cs | Culture-aware login/logout URLs; navigation tweaks. |
| modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LoginDisplay.razor | Uses computed culture-aware login URL. |
| modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LanguageSwitch.razor | Adds route-culture navigation for language switching. |
| modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BasicThemeToolbarContributor.cs | Reorders toolbar items (LoginDisplay before LanguageSwitch). |
| modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Server.BasicTheme/Themes/Basic/LoginDisplay.razor.cs | Builds login link using route-culture (server). |
| modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Server.BasicTheme/Themes/Basic/LoginDisplay.razor | Uses GetLoginUrl() for login link. |
| modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor.cs | Adds Culture route parameter binding. |
| modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor | Adds culture-prefixed @page route. |
| modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorUserMenuContributor.cs | Switches menu URL to ~/... form (for prefixing). |
| framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Localization/RouteBasedCultureTestModule.cs | Test module enabling route-based culture. |
| framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Localization/RouteBasedCulture_Tests.cs | Verifies culture selection + cookie behavior. |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/RouteBasedCultureUrlHelper_Tests.cs | Tests culture-prefixing URL helper (WASM). |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/RouteBasedCultureNavigationHelper_Tests.cs | Tests route-culture navigation helper behavior. |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/RouteBasedCultureApiRouting_Tests.cs | Ensures API routing not intercepted by culture routes. |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/LanguageSwitchRouteCultureReplacement_Tests.cs | Tests returnUrl culture replacement (route + query). |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/AbpLanguagesController_Tests.cs | Tests /Abp/Languages/Switch route-culture replacement. |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/AbpCultureMenuItemUrlProvider_Tests.cs | Tests menu URL culture prefixing provider. |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/AbpCultureAwareUrlHelper_Tests.cs | Tests URL helper culture injection wrapper/factory. |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs | Enables route-based culture in MVC test host. |
| framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj | Adds reference needed for WASM helpers in tests. |
| framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs | Runs URL providers after menu configuration. |
| framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuItemUrlProviderContext.cs | Adds context object for URL providers. |
| framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuItemCulturePrefixHelper.cs | Adds recursive URL prefix helper for menus. |
| framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/IMenuItemUrlProvider.cs | Introduces post-processing hook for menu item URLs. |
| framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/IMenuItemCulturePrefixHelper.cs | Interface for menu culture-prefix helper. |
| framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/DefaultAbpRequestLocalizationOptionsProvider.cs | Inserts RouteDataRequestCultureProvider when enabled. |
| framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationOptions.cs | Adds UseRouteBasedCulture option. |
| framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationMiddleware.cs | Persists culture + HasRouteCulture cookie for Blazor SSR. |
| framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestCultureCookieHelper.cs | Adds HasRouteCulture cookie + route-culture helper. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/QueryStringCultureReplacementContext.cs | Adds CurrentCulture for smarter replacement. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpLanguagesController.cs | Uses cookie-derived current culture for returnUrl replacement. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpCultureRouteUrlHelperFactory.cs | Wraps URL helper factory to inject culture route values. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpCultureRoutePagesConvention.cs | Adds {culture} selector to Razor Pages routes. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpCultureRouteConstraint.cs | Adds culture constraint based on configured languages. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpCultureMenuItemUrlProvider.cs | Prefixes menu URLs with culture when enabled. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpCultureAwareUrlHelper.cs | Wraps IUrlHelper to auto-inject culture values. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpAspNetCoreMvcQueryStringCultureReplacement.cs | Replaces route-culture + query-string culture values in returnUrl. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs | Exposes UseRouteBasedCulture via app configuration DTO. |
| framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | Registers route constraint, MVC culture route, pages convention, URL helper factory. |
| framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs | Adds UseRouteBasedCulture field. |
| framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/RouteBasedCultureUrlHelper.cs | Adds culture-prefix URL helper for WASM. |
| framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/RouteBasedCultureNavigationHelper.cs | Adds culture-switch navigation helper for WASM. |
| framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IRouteBasedCultureUrlHelper.cs | Interface for WASM culture-prefix URL helper. |
| framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IRouteBasedCultureNavigationHelper.cs | Interface for WASM culture-switch navigation helper. |
| framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Volo.Abp.AspNetCore.Components.WebAssembly.Theming.csproj | Adds authentication package dependency for theming helpers. |
| framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/CultureAwareRedirectToLoginHelper.cs | Centralizes culture-aware redirect-to-login logic. |
| framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/CultureAwareAuthenticationBase.cs | Base class for culture-aware WASM authentication pages. |
| framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/AbpWasmCultureMenuItemUrlProvider.cs | Prefixes menu URLs with culture in WASM (browser-only). |
| docs/en/framework/fundamentals/url-based-localization.md | Adds full documentation for URL-based localization. |
| docs/en/framework/fundamentals/localization.md | Links to URL-based localization doc. |
| docs/en/framework/fundamentals/index.md | Adds URL-based localization to fundamentals index. |
| docs/en/Community-Articles/2026-03-29-Url-Based-Localization/POST.md | Adds community article describing feature and usage. |
| docs/en/Community-Articles/2026-03-29-Url-Based-Localization/images/module-identity-users.png | Adds documentation image asset. |
|
Images automagically compressed by Calibre's image-actions ✨ Compression reduced images by 79.1%, saving 401.6 KB.
6 images did not require optimisation. |
|
Hello @fahrigedik I have just updated the Angular part for this implementation. I have also created a PR for the lepton-x theme https://github.com/volosoft/lepton/pull/3451. That would be the best if you could review the code 🙏🏻 |
Add URL-based localization support that embeds the culture code directly in the URL path (e.g.
/tr/identity/users). Enabled with a single configuration:When enabled, ABP automatically handles route registration, URL generation, menu links, and language switching for MVC, Razor Pages, Blazor Server, and Blazor WebApp (WASM).
For Blazor pages,
@page "/{culture}/..."route variants need to be added manually. All ABP built-in module pages already include these routes.Related PRs:
Documentation:
Notes for the Angular team
A new boolean field
useRouteBasedCulturehas been added to the/api/abp/application-configurationresponse, under thelocalizationobject:{ "localization": { "useRouteBasedCulture": true, ... } }This flag indicates that the server has
UseRouteBasedCulture = trueconfigured. When this flag istrue, the Angular app should:Prefix all routes with
/:culture— Add a/:cultureparent route segment so that URLs like/tr/identity/usersare routed correctly.Update the language switcher — Instead of only calling
sessionState.setLanguage(cultureName), also navigate to the same page under the new culture prefix (e.g./tr/identity/users→/en/identity/users).Update internal navigation calls — Any
router.navigate()call that produces an absolute path (e.g.router.navigate(['/identity/security-logs'])) should prepend the current culture segment whenuseRouteBasedCultureistrue.No API endpoint changes are needed — routes like
/api/...are unaffected.