Skip to content

Commit 84700e4

Browse files
chore(localization): update for WASM preview 4
1 parent 7e4623a commit 84700e4

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

globalization/localization.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,28 @@ Telerik provides and supports the default English texts. The offline demos carry
3131

3232
When localizing a Blazor app, make sure you are familiar with the way localization works in the framework. You can start from the following resources:
3333

34-
* [Localization in Blazor](https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.0#localization)
34+
* [Globalization and Localization in Blazor](https://docs.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-3.1)
3535
* [Localization in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.0)
3636

37+
>tip You can find sample runnable projects for both server-side Blazor and for WebAssembly in the [Telerik Blazor UI Samples Repo](https://github.com/telerik/blazor-ui/tree/master/common/localization/).
38+
>
39+
>You can also find an example server-side implementation in our offline demos project that are available your Telerik UI for Blazor installation (both [msi]({%slug installation/msi%}) and [zip]({%slug installation/zip%})).
40+
41+
42+
### Walkthrough - How to Add Globalization and Localization to a Server-side Blazor App
43+
44+
This section will show a tutorial on how to add globalization and localization to a server-side Blazor app. For a WebAssemly app, chek out the [ClientLocalizationResx sample project](https://github.com/telerik/blazor-ui/tree/master/common/localization/ClientLocalizationResx).
45+
3746
The necessary steps are to:
3847

3948
1. Enable the .NET Core localization services.
4049
1. Implement the UI culture storage (for example, a cookie).
4150
1. Optionally, add UI that will let the user change the culture so you can test how this works (for example, a dropdownlist that will redirect to the appropriate controller). Alternatively, you can hardcode the `options.DefaultRequestCulture` in the `ConfigureServices` method inside `Startup.cs` when generating the options for the framework localization service.
4251
1. Implement a service for localizing the Telerik components - it must return the desired string based on the current culture and the requested key (see the explanations above).
4352

44-
>note The code snippets below will showcase a sample implementation for a server-side app. For a client-side app, some framework configurations my differ and you cannot use `.resx` files because the framework does not support them.
4553

46-
>tip You can find an example implementation in our offline demos project that are available your Telerik UI for Blazor installation (both [msi]({%slug installation/msi%}) and [zip]({%slug installation/zip%})).
47-
>
48-
> More examples are available in the following repo: [https://github.com/telerik/blazor-ui/tree/master/common/localization/](https://github.com/telerik/blazor-ui/tree/master/common/localization/).
4954

50-
>note When following this tutorial to add localization to an existing app, make sure to compare the configuration you are copying so that you do not remove configuration necessary for your app.
55+
>note When following this tutorial to add localization to an existing app, make sure to compare the configuration you are copying so that you do not remove configuration necessary for your app. Code comments and regions explain details.
5156
5257
>caption Step 1 - Example for enabling localization in the app
5358
@@ -148,10 +153,7 @@ public class CultureController : Controller
148153
{
149154
HttpContext.Response.Cookies.Append(
150155
CookieRequestCultureProvider.DefaultCookieName,
151-
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture("en-US", culture)));
152-
// for the time being the thread culture is hardcoded to "en-US"
153-
// until culture-aware number and date formats are implemented
154-
// so here we only change the UICulture of the thread to the new culture
156+
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture, culture)));
155157
}
156158

157159
return LocalRedirect(redirectUri);
@@ -247,9 +249,11 @@ public class CultureController : Controller
247249

248250
>caption Step 4 - Sample Telerik localization service implementation - this example relies on a `~/Resources` folder with the necessary `.resx` files.
249251
250-
>important You must implement the indexer only. You can obtain the needed strings from any source you prefer and that matches you application, such as database, `resx` files (not supported in client-side projects at the time of writing), `json` files, hash tables, and so on.
252+
>tip You must implement the indexer only. You can obtain the needed strings from any source you prefer and that matches your application needs, such as database, `resx` files, `json` files, hash tables, and so on.
251253
252254
````CS
255+
using Telerik.Blazor.Services;
256+
253257
public class SampleResxLocalizer : ITelerikStringLocalizer
254258
{
255259
// this is the indexer you must implement
@@ -278,7 +282,7 @@ It is required that you add the resource file provided in your Telerik UI for Bl
278282
Make sure to:
279283

280284
* Mark the `resx` files as `Embedded Resource` (right click > Properties > Build Action).
281-
* Have the following in your `ProjectName.csproj` file so the designer file is generated (it should be added when you add the main messages file, or when you open and save it. Copy the snippet in case it is not added). If the `Designer` file does not get generated, open the `resx` file in Visual Studio and toggle its `Access Modifier` to `Public`.
285+
* Have the following in your `ProjectName.csproj` file so the designer file is generated. It should be added when you add the main messages file, or when you open and save it. Copy the snippet in case it is not added. If the `Designer` file does not get generated, open the `resx` file in Visual Studio and toggle its `Access Modifier` to `Public`.
282286

283287
**XML**
284288

0 commit comments

Comments
 (0)