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

WebLaF messes up the Java Default Locale #457

Closed
manticore-projects opened this issue Jun 2, 2017 · 9 comments
Closed

WebLaF messes up the Java Default Locale #457

manticore-projects opened this issue Jun 2, 2017 · 9 comments

Comments

@manticore-projects
Copy link

OS

are@localhost ~> locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

JDK/Java:

System.out.println(Locale.getDefault()); // returns en_US as expected


SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          WebLookAndFeel.initializeManagers();
          System.out.println(Locale.getDefault()); // returns en_GB which is incorrect
        }
      });

SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          WebLookAndFeel.initializeManagers();
          Locale.setDefault(Locale.US);
          System.out.println(Locale.getDefault()); // returns en_US as expected, 
                                                                         // but enforces a certain locale which is 
                                                                         // unacceptable of course
        }
      });

Now, the issue is: while the language English seems to be correct, Date and Number formats are messed up completely by that. Enforcing en_US is also not an option for an software, which supports various languages. Accepting en_GB does not work either, as any other component (Database, Reports, Spreadsheets) will correctly parse/format according to en_US.

We would like to suggest to not temper with the frameworks settings as it breaks things too easily and is difficult to trace.

@mgarin
Copy link
Owner

mgarin commented Jun 2, 2017

This is a small feature integrated into LanguangeManager and enabled by default. Locale is being automatically set according to the selected language - en by default which leads to en_GB locale.

You can disable it like this:

LanguageManager.setUpdateLocale ( false );

Note that you need to do that strictly before installing L&F or initializing L&F managers, otherwise locale will be updated according to the language set in the manager.

Though I do agree that Locale management is currently quite poor, so I'll mark this issue as an enhancement and will look into that in the future updates.

@mgarin mgarin self-assigned this Jun 2, 2017
@mgarin mgarin added this to the v1.4.0 milestone Jun 2, 2017
@manticore-projects
Copy link
Author

manticore-projects commented Jun 2, 2017 via email

@manticore-projects
Copy link
Author

manticore-projects commented Jun 2, 2017 via email

@mgarin
Copy link
Owner

mgarin commented Jun 2, 2017

I'm generally referencing latest styling branch snapshot builds as all other artifacts are a least a year+ older and contain a lot of issues which have already been fixed, so I strongly recommend using newer ones.

You can find them on the snapshot maven repository:
https://oss.sonatype.org/content/repositories/snapshots/

Also newer versions contain a lot of API changes and appropriate styling system implementation for the UI, so it is much more useful for anyone who would like to customize things.

And yes, I know that versioning is in a mess right now (due to me trying to stick in too many things in one update), but I have to get through v1.2.9 release to manage all of the stuff properly in the future updates.

@mgarin
Copy link
Owner

mgarin commented Jun 2, 2017

You will have to manage quite a few locale/language pairs for English/French/German/Portuguese/Spanish that way, which ends up mostly in identical translations. Why not honor the REGION/COUNTRY settings of the JDK?

There have been a similar question some time ago in #272 - I will certainly look into possible options when I will be working on LanguageManager enhancements, but I'm not sure yet how exactly it will function.

@mgarin
Copy link
Owner

mgarin commented Jun 2, 2017

Suggestion: set the language only, but do not alter the region/country and honor especially the JVM Options.

This, unfortunately, won't always work as you would want to, so it's not a perfect solution either. But I will be looking into options when I will be working on the enhancements.

@mgarin
Copy link
Owner

mgarin commented Jun 2, 2017

Suggestion: mention it perhaps in the basic howtos/instructions. The default behavior is unexpected and hard to trace.

I will make sure to add this this to wiki along with the other changes coming with this enhancements.

@mgarin mgarin changed the title WebLAF messes up the Java Default Locale WebLaF messes up the Java Default Locale Oct 30, 2017
@mgarin mgarin modified the milestones: v1.4.0, v1.2.9 Oct 31, 2017
@mgarin
Copy link
Owner

mgarin commented Oct 31, 2017

Some major changes for LanguageManager are coming, those will address this issue and many others and will also bring a lot of overall improvements and a few new features.

You can read more about the upcoming changes here:
#272 (comment)

mgarin added a commit that referenced this issue Nov 8, 2017
`LanguageManager` was changed to allow requesting translations for multiple languages simultaneously and also to provide full support for any country codes. Big changes have also been made to features available within core `LanguageManager` and its UI counterpart - `WebLanguageManager`. Manger API was also slightly improved to reflect the changes.

JUnit tests
With this commit I have added first two JUnit tests for `LanguageManager` and `Merge` as the most intricate things within the library so far (not counting `StyleManager` but it will surely be covered later as well). I intend to add more tests in the future to cover most complicated library parts and make sure no major issues are going into any branches.

Language
- LanguageManager.java - Doesn't contain any UI-related code anymore, those have been moved into `WebLanguageManager` class
- LanguageManager.java - Doesn't change locale according to provided language anymore [ #272 #457 ]
- LanguageLocaleUpdater.java - `LanguageListener` implementation that can be used to auto-update default `Locale` with `LanguageManager` one
- Language.java - New class providing access to translations based on `Locale` it stores, multiple instances provide access to multiple languages
- LM.java - Reworked to provide convenient access to default `Language` instance or any other `Language` that is provided by customizable supplier
- LanguageListener.java - Now only provides `Language` change event instead of being all-in-one listener
- DictionaryListener.java - Now provides all `Dictionary`-related events instead of `LanguageListener`
- LanguageConstants.java - Removed as redundant, all/supported locales can now be properly requested from `LanguageManager`
- Dictionary.java - Removed `author`, `creationDate` and `notes` fields as redundant
- Dictionary.java - Now contains all transient record and dictionary caches within itself
- Dictionary.java - Renamed `languageInfos` into `translations` to reflect its actual meaning
- Dictionary.java - Added methods to retrieve "all" and "fully supported" locales
- TranslationInformation.java - Renamed from `LanguageInfo` and refactored
- TranslationInformation.java - Language replaced with `locale` field to allow using country codes (ex. `en-GB` or `en-US`)
- TranslationInformation.java - Removed `info` field as redundant
- LanguageMethods.java - Now added to all existing Web-components as it can properly apply tooltip-only translations
- JTextComponentLU.java - Now detects `IInputPrompt` interface usages in component or UI to provide translation for it
- WebTextFieldLU.java, WebPasswordFieldLU.java, WebFormattedTextFieldLU.java - Removed as redundant
- WebAbstractButtonLU.java - Removed as redundant, `AbstractButtonLU` fulfills its role now
- WebLanguageUpdater.java - Removed as redundant as hotkeys are not supported by `LanguageManager` anymore
- LanguageUpdaterSettings.java - Removed as a bad settings design, configuration remains within `JTabbedPaneLU`
- LanguageSensitive.java - New marker interface created to assist UI components with detecting language-sensitive content
- ListPainter.java, TreePainter.java, TablePainter.java - Updated to react to language-sensitive component, models, renderers and data
- language.xml - Have been replaced with separate `core`, `ui` and `demo` XML dictionaries [ #470 ]
- core-language.xml - New XML dictionary for `core` module
- ui-language.xml - New XML dictionary for `ui` module
- demo-language.xml - New XML dictionary for `demo` module
- en_GB.png, en_US.png - New language variation icons

LanguageChooser
- LanguageChooser.java - New customizable language chooser based on supported `LanguageManager` locales
- LanguageChooserModel.java - Provides a list of supported or predefined locales
- languagechooser.xml - Separate light and dark styles for `LanguageChooser`

HeatMap
- HeatMap.java - New UI debugging tool that paints rendering time heat map over the UI

Tree
- TreeWalker.java - New interface providing options to conveniently iterate `JTree` nodes
- AbstractTreeWalker.java - Abstract `TreeWalker` containing implementations for basic methods
- SimpleTreeWalker.java - `TreeWalker` implementation for simple trees like `JTree`, `WebTree` and `WebExTree`
- AsyncTreeWalker.java - `TreeWalker` implementation for `WebAsyncTree` that contains some workarounds
- TreeUtils.java - Added method to retrieve `TreeWalker` implementation compatible with provided `JTree`

Renderers
- WebListCellRenderer.java, WebTreeCellRenderer.java, WebTableCellRenderer.java - Fixed performance issues for disabled icons
- WebListCellRenderer.java, WebTreeCellRenderer.java - Added hover decoration state support

Components
- Added missing implementations for `ContainerMethods`, `EventMethods` and `ToolTipMethods`

Style
- StyleId.java, ComponentStyle.java - Expanded complete style identifier to avoid style caches overwriting each other
- StyleManager.java, StyleData.java - Fixed a critical issue that might break skins loading order
- MovingHighlightBackground.java - Added appropriate cleanup on deactivation, optimized and refactored code
- MenuItemLayout.java - It is now more flexible and can be applied to any component, not just `JMenuItem`
- RoundRectangle.java - Fixed preferred size calculation

ComboBox
- WebComboBoxModel.java - Replacement for default `DefaultComboBoxModel` with generic item type and additional methods
- ComboBoxPainter.java - Removed redundant font and background updates from painting methods
- WebComboBoxRenderer.java - Added new `pressed`, `expanded` and `collapsed` states for renderer component

MenuItem
- AbstractMenuItemLayout.java - Contains most of the code previously stored in `MenuItemLayout`
- MenuItemLayout.java - Only includes `JMenuItem`-related features now
- SimpleMenuItemLayout.java - New simplified menu item layout that is not tied to `JMenuItem` type and can be used separately

DocumentPane
- WebDocumentPane.java - Added "select" option for document open methods to allow choosing whether or not opened document tab should be selected
- PaneData.java, ui-language.xml - Added "Close all" menu option for all tabs

DateField
- WebDateFieldUI.java - Added "Escape" hotkey for closing calendar popup

Collection duplicate resolver
- DuplicateResolver.java - Base interface for any class that detects and resolves duplicates within any `Collection`
- AbstractDuplicateResolver.java - Abstract `DuplicateResolver` containing some basic methods for usage convenience
- IgnoreDuplicates.java, RejectDuplicates.java, RemoveDuplicates.java - Basic `DuplicateResolver` implementations
- DuplicateException.java - Special exception type used within `DuplicateResolver` implementations

Object matcher
- Matcher.java - Base interface for any kinds of object matchers
- AbstractMatcher.java - Abstract `Matcher` that uses generic types for matched objects
- EqualMatcher.java, IdentifiableMatcher.java, SkippingMatcher.java - Basic `Matcher` implementations

Merge
- ListMergeBehavior.java - Have been greatly improved and made configurable with `Matcher` and `DuplicateResolver` usage
- IndexListMergeBehavior.java - New simple list elements merge behavior for index-to-index merge
- Overwriting.java - Now implements `Mergeable` by default
- RelativeTypeMergePolicy.java - Renamed from `RelatedTypeMergePolicy` for convenience
- Mergeable.java, GlobalMergeBehavior.java - Minor JavaDoc improvements

Clone
- Clone.java - Added minor improvement to allow `Clone` to set final values

API
- BiPredicate.java - `BiPredicate` from JDK8 for later porting convenience

DemoApplication
- DemoApplication.java - Added `HeatMap` tool
- Updated multiple classes according to code changes

LibraryInfoDialog
- LibraryInfoDialog.java - Refactored and cleaned up code, moved styles into extension
- LibraryInfoExtension.java, LibraryInfoIconSet.java - Extension and icon set for `LibraryInfoDialog`
- info-extension.xml, info-icons.xml, java.svg - Resources for `LibraryInfoDialog`

Utilities
- ImmutableSet.java - New unmodifiable `Set` implementation
- IconUtils.java - New utility class providing methods for various icon manipulations
- FileUtils.java - Added method to filter out unwanted symbols from text for file name
- ArrayUtils.java - Added methods to compare arrays
- CollectionUtils.java - Added method to retrieve maximum element from collection according to comparator

Project
- pom.xml - Updated to include JUnit library as test dependency
- build.properties - Updated path to `LibraryInfoDialog`
- Added currently used JUnit library version and its dependencies
@mgarin
Copy link
Owner

mgarin commented Nov 8, 2017

Changes are now available in styling branch.
Locale will never be adjusted by LanguageManager by default anymore.
To return previous behavior (Locale update to current language) you can add one extra line of code:

LanguageManager.addLanguageListener ( new LanguageLocaleUpdater () );

@mgarin mgarin closed this as completed Nov 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants