On Tue, 28 Jul 2026 11:55:21 GMT, Marius Hanl <[email protected]> wrote:

>> If I want to change the locale at runtime I use my own mutable `Locale` and 
>> pass it to the relevant methods as is supported with these converters. I 
>> didn't know changing the default was common. One reason is that if you want 
>> to reset the preferences, you can read the (system) default locale, but if 
>> you change it, what do you reset to?
>
> You need to save the default system `Locale`, otherwise you can not reset it 
> correctly.
> 
>> I use my own mutable Locale and pass it to the relevant methods
> 
> This approach is reasonable with converters, but how does e.g. Java (for 
> exception messages) or JavaFX Controls know which `Locale` it should use?
> 
> Hence `Locale.getDefault()` is the 'standard' approach. And 
> `Locale.setDefault(..)` to change that.
> 
> In case you are interested, here is one approach I used in one application to 
> support changing the `Locale` and loading/saving it as setting (properties 
> file):
> 
> 
> public final class I18N {
> 
>     static {
>         String language = Settings.get().language();
>         setLocale(Locale.forLanguageTag(language));
>     }
>     
>     ...
>     
>     public final class Settings {
>     
>         private Settings() {
>             language = Locale.getDefault().getLanguage();
>         }
>         
>         ...
>         void loadSettings() { 
>             language = properties.getProperty("language", language); 
>         }
> 
>         public String language() {
>             return language;
>         }
>     
>     }
> }
> 
> 
> There is also a mechanism to set the `Locale` at runtime. 
> My example above only shows how I load the language or use the system one 
> otherwise on application start.
> 
> When I change the `Locale` at runtime, I only need to reload the UI and 
> everything is translated correctly in the new language, including JavaFX 
> controls and, also important: Decimal and thousands separators. 
> And reloading/recreating the UI is usually quite fast, so it looks nearly 
> instant.

Should I do the same with `Chronology`, as asked in 
https://github.com/openjdk/jfx/pull/1880#discussion_r3565191158?

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1880#discussion_r3684927173

Reply via email to