* fix(module: locale): fix custom locale resource * update doc * Update LocaleProvider,cs * Update i18n.zh-CN.md * Update LocaleProvider * Update docs
3.8 KiB
order | title |
---|---|
4 | 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 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
// Set current language
LocaleProvider.SetLocale("en-US");
Change locale at run time
Ant Design Blazor
can use CultureInfo.DefaultThreadCurrentUICulture
to dynamically change the localization.
// 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)
You can set default language by LocaleProvider.DefaultLanguage = "languageName"
.
You can also add a language pack by using the LocaleProvider.SetLocale
method.
// 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 |