Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick up locale requested by the client #489

Open
Kaliumhexacyanoferrat opened this issue May 23, 2024 · 1 comment
Open

Pick up locale requested by the client #489

Kaliumhexacyanoferrat opened this issue May 23, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Kaliumhexacyanoferrat
Copy link
Owner

Kaliumhexacyanoferrat commented May 23, 2024

As a developer of a localizable web application, I would like my app to pick up the locale requested by the client, so that generated content can get localized accordingly.

Example

var localization = Localization.FromHeader() // default
                               .FromQuery("lang") // FromCookie(), From...()
                               .FromRequest(r => ...)
                               .Set(culture: true, uiCulture: true)
                               .Supports(culture => true) // allow to negoiate supported cultures and ignore non-supported ones
                               .Default(CultureInfo.GetCultureInfo("hi-IN"));

Acceptance criteria

  • The functionality is implemented using a concern
  • The functionality is either implemented in the basics or in a new module (such as i18n)
  • The supported locales can be read from various places, such as query parameters or in a custom manner
  • The concern can be configured to set the .NET properties for the current culture
  • The concern can be configured to set a request property (so we do not need to rely on the .NET ones)
  • The concern allows the app to negoiate the locale to be used by filtering the requested ones
  • A default culture can be set (e.g. if none is passed by the client)
  • The functionality is covered by acceptance tests
@Kaliumhexacyanoferrat Kaliumhexacyanoferrat added the enhancement New feature or request label May 23, 2024
@Kaliumhexacyanoferrat Kaliumhexacyanoferrat changed the title Set CurrentUICulture to the requested one Pick up locale requested by the client May 23, 2024
@Matasx
Copy link

Matasx commented May 29, 2024

FYI when using docker to host the app and especially when using alpine linux, be aware that application is by default forced to run in globalization invariant mode, which causes any attempt to change the current culture in runtime to throw an expection. Furthermore the alpine base image does not contain ICU (International Components for Unicode) which is need for .net globalization to work.

The topic is described in detail on MS docker github and MS documentation.

Solutions (2 options):

  1. Use different base image that contains ICU and does not disable globalization.

  2. Force disable invariant globalization in .csproj file <InvariantGlobalization>false</InvariantGlobalization>.
    Set following ENV variable in docker file ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false (for some reason setting only one of the ENV or csproj option did not worked for me, had to set both).
    Install icu libs on top of alpine base image:

RUN apk add --no-cache \
    icu-data-full \
    icu-libs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants