On Thu, 30 Jul 2026 17:36:33 GMT, Nir Lisker <[email protected]> wrote:
>> 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?
No, I don't think so. The only Chronology instance I see created by JavaFX is
in`BaseTemporalStringConverter`:
private static final Chronology DEFAULT_CHRONO = IsoChronology.INSTANCE;
which isn't Locale-sensitive.
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/1880#discussion_r3685149912