Skip to content

Commit 16034e3

Browse files
901451: update UG content for globalization
1 parent e1a6b3b commit 16034e3

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

blazor/common/globalization.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,64 @@ documentation: ug
99

1010
# Globalization in Blazor Application
1111

12-
* Globalization is the combination of adapting the control to various languages by parsing and formatting the date or numbers (`Internationalization (L18N)`) and adding cultural-specific customizations and translating the text (`Localization (L10N)`).
12+
Globalization is the combination of adapting the control to various languages by parsing and formatting the dates, times, numbers or currencies (`Internationalization (L18N)`) and adding cultural-specific customizations and translating the text (`Localization (L10N)`).
1313

14-
* The Syncfusion Blazor UI components are specific to the `American English (en-US)` culture by default. It utilizes the `Blazor Internationalization` package to parse and format the number and date objects based on the chosen culture.
14+
The Syncfusion Blazor UI components are specific to the `American English (en-US)` culture by default. It utilizes the `Blazor Internationalization` package to parse and format the number and date objects based on the chosen culture.
15+
16+
Blazor uses the built-in .NET types from the `System.Globalization` namespace, such as the `CultureInfo` class and its `CurrentCulture` property.
17+
18+
* Culture ([CultureInfo.CurrentCulture](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.currentculture?view=net-8.0#system-globalization-cultureinfo-currentculture)): Determines the formatting of numbers, dates, and times. It's mainly concerned with how data is presented and interpreted.
19+
* UI Culture ([CultureInfo.CurrentUICulture](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.currentuiculture?view=net-8.0#system-globalization-cultureinfo-currentuiculture)): Determines the language of the user interface, including which resource files (like .resx files) are used for localizing the app’s UI.
20+
21+
When dealing with form fields in Blazor, it’s important to note that certain input types automatically respect the user's culture settings using [CultureInfo.InvariantCulture](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.invariantculture?view=net-8.0#system-globalization-cultureinfo-invariantculture).
22+
23+
For example, the following input types are culture-sensitive:
24+
25+
* `date`
26+
* `number`
27+
28+
Blazor relies on the browser’s handling of these input types, which ensures that the user input is parsed and rendered according to their specific culture settings.
29+
30+
However, some form field types are not yet fully supported across all browsers, making them less reliable in Blazor applications. These include:
31+
32+
* `datetime-local`
33+
* `month`
34+
* `week`
35+
36+
37+
The following code snippet serves as an example to demonstrate how globalization can be implemented in a Blazor application. It illustrates the process of localizing content, formatting dates and numbers.
38+
39+
{% tabs %}
40+
{% highlight razor %}
41+
42+
@page "/"
43+
@using System.Globalization
44+
45+
<ul>
46+
<li><b>CurrentCulture</b>: @CultureInfo.CurrentCulture</li>
47+
<li><b>CurrentUICulture</b>: @CultureInfo.CurrentUICulture</li>
48+
</ul>
49+
50+
<h2>Rendered values</h2>
51+
52+
<ul>
53+
<li><b>Date</b>: @dt.ToLongDateString()</li>
54+
<li><b>Number</b>: @number.ToString("N2")</li>
55+
</ul>
56+
57+
@code {
58+
private DateTime dt = DateTime.Now;
59+
private double number = 1999.69;
60+
}
61+
62+
{% endhighlight %}
63+
{% endtabs %}
1564

1665
* Suppose, if you want to change any specific culture, then add the corresponding culture resource (`.resx`) file by using the below reference.
17-
* [Changing culture and Adding Resx file in the application](https://blazor.syncfusion.com/documentation/common/localization#how-to-enable-localization-in-blazor-application)
66+
67+
[Changing culture and Adding Resx file in the application](https://blazor.syncfusion.com/documentation/common/localization#how-to-enable-localization-in-blazor-application)
68+
69+
## See also
70+
* [ASP.NET Core Blazor globalization and localization](https://learn.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-8.0)
71+
* [.NET Fundamentals: Globalization](https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization)
72+
* [.NET Fundamentals: Localization](https://learn.microsoft.com/en-us/dotnet/core/extensions/localization)

0 commit comments

Comments
 (0)