mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-12 11:55:24 +08:00
101 lines
3.8 KiB
Markdown
101 lines
3.8 KiB
Markdown
---
|
|
order: 4
|
|
title: Internationalization
|
|
---
|
|
|
|
The internationalization of `Ant Design Blazor` is based on the built-in `LocaleProvider`, and localization is based on the `CultureInfo.DefaultThreadCurrentUICulture` provided by the blazor framework.
|
|
Refer to the document [ASP.NET Core Blazor globalization and localization](https://docs.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-3.1&WT.mc_id=DT-MVP-5003987#localization) for more details.
|
|
|
|
By default, the current language is fetched from the browser. If you need to use another language, you can configure it at initialization time or change it at run time. Please refer to the following scheme.
|
|
|
|
## localization configuration
|
|
|
|
```csharp
|
|
// Set current language
|
|
LocaleProvider.SetLocale("en-US");
|
|
```
|
|
|
|
## Change locale at run time
|
|
|
|
`Ant Design Blazor` can use `CultureInfo.DefaultThreadCurrentUICulture` to dynamically change the localization.
|
|
|
|
```csharp
|
|
// Changing it anywhere can switch the language of the current thread.
|
|
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US");
|
|
```
|
|
|
|
When the language you set does not have a built-in language pack, we will fallback to the parent culture/locale, then `LocaleProvider.DefaultLanguage`, then "en-US". (To learn more about the term of parent culture, see [Globalization and localization terms](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-5.0#globalization-and-localization-terms))
|
|
|
|
You can set default language with `LocaleProvider.DefaultLanguage = "languageName"`.
|
|
|
|
You can also add a language pack by using the `LocaleProvider.SetLocale` method.
|
|
|
|
```csharp
|
|
// Set default language
|
|
LocaleProvider.DefaultLanguage = "en-US";
|
|
|
|
// Create a `Locale` object
|
|
var zhHK = new Locale { ... };
|
|
// Set an additional language
|
|
LocaleProvider.SetLocale("zh-HK", zhHK);
|
|
```
|
|
|
|
Note: `en-US` is the package name, follow below.
|
|
|
|
Built-in languages:
|
|
|
|
| Language | Package Name |
|
|
| --------------------- | -------- |
|
|
| Arabic | ar-EG |
|
|
| Armenian | hy-AM |
|
|
| Bulgarian | bg-BG |
|
|
| Catalan | ca-ES |
|
|
| Czech | cs-CZ |
|
|
| Denmark | da-DK |
|
|
| German | de-DE |
|
|
| Greek | el-GR |
|
|
| English (Global) | en-GB |
|
|
| English | en-US |
|
|
| Spanish | es-ES |
|
|
| Estonian | et-EE |
|
|
| Persian | fa-IR |
|
|
| Finnish | fi-FI |
|
|
| French (Belgium) | fr-BE |
|
|
| French (France) | fr-FR |
|
|
| Hebrew | he-IL |
|
|
| Croatian | hr-HR |
|
|
| Hindi | hi-IN |
|
|
| Hungarian | hu-HU |
|
|
| Indonesian | id-ID |
|
|
| Italian | it-IT |
|
|
| Icelandic | is-IS |
|
|
| Japanese | ja-JP |
|
|
| Georgian | ka-GE |
|
|
| Kannada | kn-IN |
|
|
| Korean | ko-KR |
|
|
| Kurdish | ku-IQ |
|
|
| Latvian | lv-LV |
|
|
| Malay | ms-MY |
|
|
| Mongolian | mn-MN |
|
|
| Norwegian | nb-NO |
|
|
| Nepal | ne-NP |
|
|
| Dutch (Belgium) | nl-BE |
|
|
| Dutch | nl-NL |
|
|
| Polish | pl-PL |
|
|
| Portuguese (Brazil) | pt-BR |
|
|
| Portuguese | pt-PT |
|
|
| Slovak | sk-SK |
|
|
| Serbian | sr-RS |
|
|
| Slovenian | sl-SI |
|
|
| Swedish | sv-SE |
|
|
| Tamil | ta-IN |
|
|
| Thai | th-TH |
|
|
| Turkish | tr-TR |
|
|
| Romanian | ro-RO |
|
|
| Russian | ru-RU |
|
|
| Ukrainian | uk-UA |
|
|
| Vietnamese | vi-VN |
|
|
| Chinese (Simplified) | zh-CN |
|
|
| Chinese (Traditional) | zh-TW |
|
|
|