Skip to content

Commit a887fa9

Browse files
update: angular documentation for url-based localization
1 parent 34d5bc1 commit a887fa9

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

docs/en/framework/fundamentals/url-based-localization.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,49 @@ Culture detection, cookie persistence, menu URLs, and language switching all wor
108108

109109
Same as Blazor Server — you must manually add `@page "/{culture}/..."` routes to your Blazor pages.
110110

111+
## Angular
112+
113+
The [ABP Angular UI](../ui/angular/quick-start.md) runs in the browser. The server still applies `UseRouteBasedCulture`; the client reads **`localization.useRouteBasedCulture`** from `/api/abp/application-configuration` (same payload as other UI types). There is no separate Angular setting.
114+
115+
### Routing
116+
117+
Angular does not add a culture segment to your route config automatically. Use **`withOptionalRouteCulturePrefix`** from **`@abp/ng.core`** so one route tree matches both **`/identity/users`** and **`/en/identity/users`** (the first path segment is matched only when it looks like a culture code, e.g. `en`, `tr`, `zh-Hans`).
118+
119+
````typescript
120+
import { Routes } from '@angular/router';
121+
import { withOptionalRouteCulturePrefix } from '@abp/ng.core';
122+
123+
const appRoutesCore: Routes = [
124+
// ... your routes (path: '', 'account', 'identity', lazy children, etc.)
125+
];
126+
127+
export const appRoutes = withOptionalRouteCulturePrefix(appRoutesCore);
128+
````
129+
130+
![Angular: routes wrapped with optional culture prefix](../../images/url-based-localization-angular-routes.png)
131+
132+
### URL → session language
133+
134+
When **`useRouteBasedCulture`** is **true**, **`RouteBasedCultureService`** (from `@abp/ng.core`) keeps the session language aligned with the first URL segment after navigation. This runs during application bootstrap and on each **`NavigationEnd`**.
135+
136+
### Menu links, breadcrumbs, and `routerLink`
137+
138+
Menu paths from **`RoutesService`** are usually **without** a culture prefix (`/identity/users`). Use the **`abpRouteCultureUrl`** pipe on **`routerLink`** (or **`RouteBasedCultureUrlService.prefixPathWithCulture`**) so links navigate to **`/en/identity/users`** when route-based culture is enabled. The **Basic** theme navigation and **Theme Shared** breadcrumb links follow this pattern.
139+
140+
![Angular: culture-prefixed menu or URL bar](../../images/url-based-localization-angular-menu-url.png)
141+
142+
### Language switcher (toolbar)
143+
144+
If the user selects a language in the UI, call **`RouteBasedCultureUrlService.applyLanguageSelection(cultureName)`** (or **`navigateToUrlWithCulture`**) instead of only updating the session language. That rewrites the current URL’s culture segment (or prepends it) so the address bar and session stay consistent; **`RouteBasedCultureService`** then picks up the culture from the URL after navigation.
145+
146+
### Active menu, breadcrumbs, and route matching
147+
148+
The browser URL may be **`/en/identity/users`** while menu items and **`RoutesService`** paths stay **`/identity/users`**. For comparisons (active state, **`findRoute`**, permission guard, dynamic layout), normalize the current URL with **`RouteBasedCultureUrlService.normalizeForMenuMatch`** (or **`stripCulturePrefixIfEnabled`**) or use **`getRoutePathForMatching`** where **`getRoutePath`** was used.
149+
150+
### Configuration refresh
151+
152+
**`RouteBasedCultureUrlService`** refreshes its cached **`useRouteBasedCulture`** and **languages** when application configuration is updated (for example after **`refreshAppState`**), so hot paths do not query configuration on every change detection cycle.
153+
111154
## Multi-Tenancy Compatibility
112155

113156
URL-based localization is fully compatible with [multi-tenancy URL routing](../architecture/multi-tenancy/index.md). The culture route is registered as a conventional route `{culture}/{controller}/{action}`. If your application uses tenant routing (e.g., `/{tenant}/...`), the tenant middleware strips the tenant segment before routing, and the culture segment is handled separately.
153 KB
Loading
355 KB
Loading

0 commit comments

Comments
 (0)