myesn

myEsn2E9

hi
github

ABP Localization Language

Conventions#

The localized key names are arbitrary. You can set any name. However, there are some conventions for specific types of text:

  1. Add the prefix Menu: to menu items.
  2. Use the naming convention <enum-type>.<enum-value> or Enum:<enum-type>.<enum-value> to localize enum members. When you do this, ABP can automatically locate the enum in some appropriate cases.

Reference

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's XXDomainSharedModule.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:
image

There is another way, which is to use https://github.com/maliming/Owl.Abp.CultureMap

I haven't used it yet.

References:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.