Skip to content

Commit a0e0843

Browse files
dimodidimodi
authored andcommitted
revamp complete
1 parent a10d6b2 commit a0e0843

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

globalization/localization.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ The `Telerik.UI.for.Blazor` NuGet package includes a [`Telerik.Blazor.Resources.
2626

2727
## Localize Telerik Blazor Components
2828

29-
This tutorial assumes that the [Telerik resource files](#step-2-add-resouce-files) reside in `~/Resources/` and have names like `TelerikMessages.<locale>.resx`. It is possible to use different file and folder names. This will affect the name of the generated static class in `TelerikMessages.Designer.cs`, and the namespaces in the [Telerik localization service](#step-3-implement-itelerikstringlocalizer-service).
29+
The tutorial below assumes that:
30+
31+
* The Blazor app name and the root namespace is `ServerLocalizationResx`.
32+
* The [Telerik resource files](#step-2-add-resouce-files) exist in folder `~/Resources/` and have names like `TelerikMessages.<locale>.resx`.
33+
34+
Using your own names is possible and will affect:
35+
36+
* The class name and file name of the auto generated designer class (for example, `TelerikMessages` in `TelerikMessages.Designer.cs`)
37+
* The used namespace and class in the [Telerik localization service](#step-3-implement-itelerikstringlocalizer-service) (for example, `AppName.Resources` and `TelerikMessages`)
3038

3139
### Step 1: Set the Blazor App Culture
3240

@@ -118,21 +126,61 @@ builder.Services.AddTelerikBlazor();
118126
builder.Services.AddSingleton(typeof(ITelerikStringLocalizer), typeof(SampleResxLocalizer));
119127
```
120128

129+
### Step 5: Inject Your Localization Service
130+
131+
This step is optional. You need it to manually render localized strings from the Telerik resource files. For example, the Telerik resource files include keys for the [built-in Grid commands]({%slug components/grid/columns/command%}).
132+
133+
* Import the `Telerik.Blazor.Services` namespace.
134+
* Inject your `ITelerikStringLocalizer` service.
135+
* Import the namespace of your Telerik localization `designer.cs` class.
136+
137+
>caption Localized .razor file with Telerik Blazor components
138+
139+
<div class="skip-repl"></div>
140+
141+
````CSHTML
142+
@using ServerLocalizationResx.Resources
143+
144+
@using Telerik.Blazor.Services
145+
@inject ITelerikStringLocalizer TelerikLocalizer
146+
147+
<p>Localized Strings from Telerik Resource Files</p>
148+
149+
<TelerikButton>@TelerikLocalizer[nameof(TelerikMessages.Grid_Edit)]</TelerikButton>
150+
<TelerikButton>@TelerikLocalizer[nameof(TelerikMessages.Grid_Update)]</TelerikButton>
151+
152+
<p>Localized Strings in Telerik Blazor Components</p>
153+
154+
<TelerikFilter @bind-Value="@FilterValue">
155+
<FilterFields>
156+
<FilterField Name="DumyField" Type="@typeof(string)" />
157+
</FilterFields>
158+
</TelerikFilter>
159+
160+
<br />
161+
162+
<TelerikFileSelect />
163+
164+
@code {
165+
private Telerik.DataSource.CompositeFilterDescriptor FilterValue { get; set; } = new();
166+
}
167+
````
121168

122169
## Examples
123170

124171
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/):
125172

126-
* <a href="https://github.com/telerik/blazor-ui/tree/master/common/localization/ServerLocalizationResx" target="_blank">Blazor Web App with Server render mode</a>
127-
* <a href="https://github.com/telerik/blazor-ui/tree/master/common/localization/ClientLocalizationResx" target="_blank">Blazor WebAssembly Standalone App</a>
173+
* <a href="https://github.com/telerik/blazor-ui/tree/master/common/localization/ServerLocalizationResx" target="_blank">Localized Telerik Blazor Web App with Server render mode</a>
174+
* <a href="https://github.com/telerik/blazor-ui/tree/master/common/localization/ClientLocalizationResx" target="_blank">Localized Telerik Blazor WebAssembly Standalone App</a>
128175

129176
You can also find a localization implementation in the offline version of the [Telerik UI for Blazor demos](https://demos.telerik.com/blazor-ui). Check your Telerik UI for Blazor installation folder or visit [UI for Blazor automated installer]({%slug installation/msi%}) or [UI for Blazor ZIP archive]({%slug installation/zip%}) for download instructions.
130177

131178

132179
## Troubleshooting
133180

181+
Outdated Telerik resource files may cause [some UI labels to appear in English]({%slug common-kb-partial-localization%}), or the app may trigger a [`Value cannot be null. (Parameter 'format')` exception]({%slug common-kb-value-cannot-be-null-parameter-format%}).
134182

135-
* This is not related to the Telerik components, but our experience shows that setting `ResourcePath` in `services.AddLocalization()` may break the standard `IStringLocalizer` in your app.
183+
This is not related to the Telerik components, but setting `ResourcePath` in `services.AddLocalization()` may break the standard `IStringLocalizer` in your app or make it more difficult to use.
136184

137185

138186
## See Also

0 commit comments

Comments
 (0)