Conventions#
The localized key names are arbitrary. You can set any name. However, there are some conventions for specific types of text:
- Add the prefix
Menu:
to menu items. - Use the naming convention
<enum-type>.<enum-value>
orEnum:<enum-type>.<enum-value>
to localize enum members. When you do this, ABP can automatically locate the enum in some appropriate cases.
Set Default Localization Language#
Because ABP comes with many language packs, but we don't need so many languages. Generally, there are only two languages, English and Chinese. The rest need to be deleted. But for Chinese, there are many branches. How do you determine what your localization language is? Determine it by executing navigator.language
in the browser. For example, if my output result is zh-CN
, it means that the json language pack file with culture
set to zh-CN
will be used, such as zh-CN.json
. This whole process is automated and does not require any configuration. Just be careful not to delete the language pack of your culture
, otherwise only English will be displayed.
I previously wanted to specify a default culture
for the project, but it was not successful. The methods I have used include:
- Configuring in the
XXW.XXX.Domain.Shared
project'sXXDomainSharedModule.ConfigureServices
function:
options.Resources
// Add localization and specify the default localization language
// https://docs.abp.io/en/abp/latest/Localization#inherit-from-other-resources
.Add<IDCloudResource>("zh-CN")
.AddBaseTypes(typeof(AbpValidationResource))
.AddVirtualJson("/Localization/IDCloud");
- Configuring the following content in the
appsettings.json
file of the*.Web
project:
{
"Settings": {
// https://github.com/abpframework/abp/issues/2469#issuecomment-569518267
"Abp.Localization.DefaultLanguage": "zh-CN"
}
}
It is also possible that the default localization language is set in the AbpSettingDefinitions
table in the database when initializing data. I accidentally saw that it has not been changed, so you can try changing it:
There is another way, which is to use https://github.com/maliming/Owl.Abp.CultureMap
I haven't used it yet.
References: