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

Misleading comment on SetPrincipalAppLanguageForRequest -- updateThreadCulture boolean appears to have no effect #384

Open
jnpwly opened this issue Apr 14, 2019 · 1 comment

Comments

@jnpwly
Copy link

jnpwly commented Apr 14, 2019

In the HttpContextExtensions.cs file, there is a comment that by setting the updateThreadCulture boolean, the user can change whether the CurrentCulture/CurrentUICulture settings can be changed:

public static void SetPrincipalAppLanguageForRequest(this System.Web.HttpContextBase context, ILanguageTag pal, bool updateThreadCulture = true)

However, this boolean ultimately has no impact; it is not actually used in the method.

It's not clear to me what the intention with this boolean was. Was it meant to allow the end user to ultimately change just the Thread.CurrentThread.CurrentCulture and not the Thread.CurrentThread.CurrentUICulture? Or, was there something else in mind?

I am more than happy to submit a PR that changes the comment, to indicate that it doesn't do anything. That's the easiest thing to do. Probably can't just remove the boolean, as that might break existing usages of the i18n library. Alternatively, I could work on developing a PR that attempts to only update the Thread.CurrentThread.CurrentCulture and not the Thread.CurrentThread.CurrentUICulture. But, seeing as the library user can implement their own SetPrincipalAppLanguageForRequestHandler, then maybe that is the method that end users should use to avoid changing the UI Culture??

@jnpwly jnpwly changed the title Misleading comment on SetPrincipalAppLanguageForRequest -- updateThreadCulture boolean appears to have no effect Misleading comment on SetPrincipalAppLanguageForRequest -- updateThreadCulture boolean appears to have no effect Apr 14, 2019
@turquoiseowl
Copy link
Owner

I suspect the SetPrincipalAppLanguageForRequest method has evolved somewhat.

It's original purpose was two-fold:

  1. To explicitly set the PAL that i18n is to use for generating the response to the current request, overriding any PAL determined from eraly request processing.
  2. To optionally invoke the following:
    Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = langtag.GetCultureInfo();

Looks like 2. was then moved to the handler model with a default handler installed to invoke that default logic -- but updateThreadCulture wasn't adpated at the same time.

I suspect most clients will probably NOT install their own handlers and just expect the default handler here to update the cultures if updateThreadCulture == true.

Maybe the best way forward is:

  1. Remove the updateThreadCulture argument from existing methods. That will break the API but not behaviour that is according to spec.
  2. Add new method: SetPrincipalAppLanguageForRequestWithoutCallingHandlers that does what it says.

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

No branches or pull requests

2 participants