Here comes two questions:
(1) Is Application.CurrentCulture read only ?
When type this code “Application.CurrentCulture” in Visual Studio, the pop-up help show me that “Returns or set the culture information for the current thread.” but then when I continue to type the code as Application.CurrentCulture = someValue;” it show me an error because this property is read only. (Refer to the attached JPG for details).
(2) I set CultureInfo.DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture to the same value (e.g. “zh-HK” or “zh-TW”). However, I got different value from Application.CurrentCulture (such as “en-US”) in different area of the programs (in the same session). E.g. I get “zh-HK” from the Desktop Onload() method and then get “en-US” from a Form Onload() method (opened by clicking the a button of the Desktop).
So, is CultureInfo.DefaultThreadCurrentCulture and/or CultureInfo.DefaultThreadCurrentUICulture effective in an WiseJ application?
Why sometimes Application.CurrentCulture return a value different from what I set to these two “CultureInfo.DefaultThread…” properties?
Because of (1) and (2), I currently not use Application.CurrentCulture at all. I set CultureInfo.DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture in the Main() method of Program. Whenever there is a new session it will use this default culture for the session. If the user change the UI language (by selecting from the MenuBar of the Desktop) I keep the culture name in the Session object and process the required logic to change the text (and formatting of Date, number, etc.) of the UI.
Hi Felix, see below:
1) Application.CurrentCulture is read-only, the comment is wrong. The writing is internal.
It is updated on every incoming request and it sets the current thread CurrentCulture and CurrentUICulture.
The culture set for the current thread is determined as described at the bottom of this page: https://docs.wisej.com/docs/concepts/localization
2) CultureInfo.DefaultThreadCurrentCulture is different it “Gets or sets the default culture for threads in the current application domain.” Which is basically the Application Pool. It’s not useful to change that since different threads may need difference cultures.
If you check Thread.CurrentThread.CurrentCulture it is the same as Application.CurrentCulture, unless the thread is an out-of-bound thread, meaning
it is not created by a request from the client. In .NET the only culture that is used is the CurrentThread.CurrentCulture and for the UI resources is CurrentThread.CurrentUICulture.
Both of those are kept in sync by Wisej when a request comes in and is assigned to a thread.
You can change the culture in many ways:
– Default.json culture property. When “auto”, Wisej recognizes the culture of the Browser: English Browsers will see english formatted dates and numbers while French browsers will se a different formatting.
– You can force the language switch by adding the lang argument to the URL (see docs above). You need a URL reload to swap languages because all widgets have to be recreated.
However, if your pages or windows are localized and have been already created, their language will not change since the resources managed to the controls is created only once at InitializeComponent(). So a language switch will need you to close and recreated windows or pages.
Please login first to submit.