You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: globalization/localization.md
+53-38Lines changed: 53 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,9 @@ The necessary steps are to:
40
40
41
41
>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.
42
42
43
-
>tip You can find an example implementation in our offline demos project that you can find your Telerik UI for Blazor installation.
43
+
>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%})).
44
+
45
+
>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.
44
46
45
47
>caption Step 1 - Example for enabling localization in the app
46
48
@@ -59,12 +61,11 @@ public class Startup
59
61
{
60
62
// define the list of cultures your app will support
// for the time being the thread culture is hardcoded to "en-US"
148
+
// until culture-aware number and date formats are implemented
149
+
// so here we only change the UICulture of the thread to the new culture
143
150
}
144
151
145
152
returnLocalRedirect(redirectUri);
@@ -154,7 +161,7 @@ public class CultureController : Controller
154
161
}
155
162
````
156
163
157
-
>caption Use a cookie to store the culture choice of the user - in this example - in `~/Pages/_Host.cshtml`
164
+
>caption Step 2 (continued) - Use a cookie to store the culture choice of the user - in this example - in `~/Pages/_Host.cshtml`
158
165
159
166
````CSHTML
160
167
@using Microsoft.AspNetCore.Localization
@@ -177,7 +184,7 @@ public class CultureController : Controller
177
184
</body>
178
185
````
179
186
180
-
>caption Sample UI component for changing cultures
187
+
>caption Step 3 - Sample UI component for changing cultures
181
188
182
189
````
183
190
@using System.Threading
@@ -193,6 +200,10 @@ public class CultureController : Controller
193
200
TextField="@nameof(CultureData.Text)"
194
201
ValueField="@nameof(CultureData.Value)">
195
202
</TelerikDropDownList>
203
+
<br />
204
+
Current UI culture (used for localization): @Thread.CurrentThread.CurrentUICulture.Name
205
+
<br />
206
+
Current thread culture (used for date and number formatting): @Thread.CurrentThread.CurrentCulture.Name
196
207
</div>
197
208
198
209
@code{
@@ -205,8 +216,7 @@ public class CultureController : Controller
205
216
public List<CultureData> Cultures { get; set; } = new List<CultureData>()
206
217
{
207
218
new CultureData() { Text = "English", Value = "en-US" },
208
-
new CultureData() { Text = "German", Value = "de-DE" },
209
-
new CultureData() { Text = "Spanish", Value = "es-ES" },
219
+
new CultureData() { Text = "French", Value = "fr-FR" },
210
220
new CultureData() { Text = "Bulgarian", Value = "bg-BG" },
211
221
};
212
222
@@ -230,14 +240,14 @@ public class CultureController : Controller
230
240
}
231
241
````
232
242
233
-
>caption Sample Telerik localization service implementation - this example relies on a `~/Resources` folder with the necessary `.resx` files.
243
+
>caption Step 4 - Sample Telerik localization service implementation - this example relies on a `~/Resources` folder with the necessary `.resx` files.
234
244
235
245
>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.
>caption Add `.resx` files to the `~/Resources` folder
267
+
>caption Step 4 (continued) - Add `.resx` files to the `~/Resources` folder
258
268
259
-
In this example the files must be named `~/Resources/TelerikMessages.<culture-locale>.resx`, for example `TelerikMessages.bg-BG.resx`. Make sure to
269
+
In this example the files must be named `~/Resources/TelerikMessages.<culture-locale>.resx`, for example `TelerikMessages.bg-BG.resx`. You can use different names (for example, in our demos we use `Messages.resx`). The file names affect the static class that is generated and how you use it in your code (for example, to localize other elements you define yourself, such as grid command buttons or your own buttons).
260
270
261
-
* mark them as `Embedded Resource`
262
-
* add this in your `ProjectName.csproj` file so they are built
271
+
It is required that you add the resource file provided in your Telerik UI for Blazor installation that matches the version used in your project. This is the file that contains the current set of localizable strings and whose designer file must be generated by the build.
* Mark the `resx` files as `Embedded Resource` (right click > Properties > Build Action).
276
+
* 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).
0 commit comments