Open Closed

Continuation of #2320 Can't set culture / language by using Accept-Language header #2361


User avatar
0
alex@livemobility.com created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v4.4.0
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • I'm using ABP commercial.

I couldn't reopen this question: https://support.abp.io/QA/Questions/2320/Can%27t-set-culture---language-by-using-Accept-Language-header

Basically I still didn't figure out how to get the accept language header to work. I tried to use the es language code, which is configured automatically by the project, but I still get all exceptions / texts in en US


2 Answer(s)
  • User Avatar
    0
    alex@livemobility.com created

    In the end I managed to get it working by moving app.UseAbpRequestLocalization(); to be the first middleware. Honestly, I'm not sure if this ok. Also, the previous call came from the abp commercial startup template.

    Also as second note, it's confusing right now how a language needs to be added. I identified the following steps:

    • create a new file under the domain project
    • add the new language in {{my}DomainModule
    • add the new language in {{my}HttpApiHostModule
    • create a record in the database by using the Language UI

    Are this the right steps?

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    In the end I managed to get it working by moving app.UseAbpRequestLocalization(); to be the first middleware. Honestly, I'm not sure if this ok. Also, the previous call came from the abp commercial startup template.

    Hi @alex@livemobility.com, there is not any problem to be the AbpRequestLocalizationMiddleware being the first middleware.

    Also as second note, it's confusing right now how a language needs to be added.
    I identified the following steps:

    • create a new file under the domain project
    • add the new language in {{my}DomainModule
    • add the new language in {{my}HttpApiHostModule
    • create a record in the database by using the Language UI

    Are this the right steps?

    • You can either add new languages via creating a new localization file under the *.Domain.Shared project (/Localization/{your-folder-name}/{language-name}.json, like en.json file) or using the Language Management module.

    • If you want to define new localization language/culture by creating a new localization file under the Localization folder of the *.Domain.Shared project, first you need to create a file under the Localization folder and then you need to define it in your *HttpApiHostModule's ConfigureLanguage method:

    private void ConfigureLocalization()
    {
         Configure<AbpLocalizationOptions>(options =>
         {
              options.Languages.Add(new LanguageInfo("ar", "ar", "العربية", "ae"));
              options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
              options.Languages.Add(new LanguageInfo("en", "en", "English"));
              options.Languages.Add(new LanguageInfo("fi", "fi", "Finnish", "fi"));
              options.Languages.Add(new LanguageInfo("fr", "fr", "Français", "fr"));
              options.Languages.Add(new LanguageInfo("hi", "hi", "Hindi", "in"));
              options.Languages.Add(new LanguageInfo("it", "it", "Italiano", "it"));
              options.Languages.Add(new LanguageInfo("sl", "sl", "Slovenščina"));
              options.Languages.Add(new LanguageInfo("sk", "sk", "Slovak", "sk"));
              options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
              options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
              options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
              options.Languages.Add(new LanguageInfo("de-DE", "de-DE", "Deutsche", "de"));
              options.Languages.Add(new LanguageInfo("es", "es", "Español", "es"));
              
              // add new localization language that you've define like above
         });
    }
    
    
    • Then you can use it in your angular UI, follow this documentation to see how you can use it on your angular UI.

    • If you define a new localization language/culture by using the Language Management module (Languages page), and update the texts for that newly created localization language you can directly use it in your Angular UI.
Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11