-
Notifications
You must be signed in to change notification settings - Fork 191
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
Use browser locale for floating point numbers formatted String.format() in UI #857
Use browser locale for floating point numbers formatted String.format() in UI #857
Conversation
targetPercentage.setValue(String.format(getCurrentLocale(), "%.2f", group.getTargetPercentage())); | ||
// necessary due the format must contain a dot and other locals might | ||
// use a comma | ||
targetPercentage.setValue(String.format(Locale.ENGLISH, "%.2f", group.getTargetPercentage())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
final UI currentUI = UI.getCurrent(); | ||
return currentUI == null ? Locale.getDefault() : currentUI.getLocale(); | ||
final Page page = Page.getCurrent(); | ||
return page == null ? Locale.getDefault() : page.getWebBrowser().getLocale(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls double-check if defaultLocale config property is still accepted...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if prop is set, it takes precedence... otherwise browser locale, otherwise system locale
|
||
/** | ||
* Default localization | ||
*/ | ||
private String defaultLocal = "en"; | ||
private String defaultLocal = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* List of available localizations | ||
*/ | ||
private List<String> availableLocals = Collections.singletonList("en"); | ||
public Localization(final List<Resource> locales) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0c569a0
to
033dcf0
Compare
* localization files (message.properties) as resources | ||
*/ | ||
public UiProperties(@Value("classpath*:messages_*.properties") final Resource[] localesResources) { | ||
this.localization = new Localization(Arrays.asList(localesResources)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check with the new spring vaadin integration if there is another solution
@@ -596,7 +596,7 @@ public static Locale getLocaleToBeUsed(final UiProperties.Localization localizat | |||
*/ | |||
public static void initLocalization(final UI ui, final Localization localizationProperties, | |||
final VaadinMessageSource i18n) { | |||
ui.setLocale(HawkbitCommonUtil.getLocaleToBeUsed(localizationProperties, ui.getSession().getLocale())); | |||
ui.setLocale(getLocaleToBeUsed(localizationProperties, Page.getCurrent().getWebBrowser().getLocale())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need to get the current page to get the desired locale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use ui.getPage()
instead of Page.getCurrent()
here, not to search for the UI one more time.
hawkbit-ui/src/test/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtilTest.java
Show resolved
Hide resolved
return new Locale(localizationProperties.getDefaultLocal()); | ||
return localizationProperties.getDefaultLocal() == null | ||
? desiredLocale | ||
: localizationProperties.getDefaultLocal(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this change the logic, because before the browser-locale had the highest priority.
Would it be possible so set fallbackToSystemLocale=false and completely rely on spring's MessageSource-management. Then that the code and properties used to determine the locale would become obsolete?
@@ -596,7 +595,7 @@ public static Locale getLocaleToBeUsed(final UiProperties.Localization localizat | |||
*/ | |||
public static void initLocalization(final UI ui, final Localization localizationProperties, | |||
final VaadinMessageSource i18n) { | |||
ui.setLocale(HawkbitCommonUtil.getLocaleToBeUsed(localizationProperties, ui.getSession().getLocale())); | |||
ui.setLocale(getLocaleToBeUsed(localizationProperties, ui.getPage().getWebBrowser().getLocale())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ui.getSession().getLocale() was the right choice here. According to the doc this returns "the preferred locale of the user (...). In most cases it is read from the browser"
@@ -63,26 +63,26 @@ public void setFixedTimeZone(final String fixedTimeZone) { | |||
/** | |||
* Default localization | |||
*/ | |||
private String defaultLocal = "en"; | |||
private Locale defaultLocal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default used to be English, is it intended that it is now null?
@a-sayyed please check the commit history, if all commits have a 'signed-off' to it |
Signed-off-by: Ahmed Sayed <[email protected]>
d917985
to
7d59344
Compare
Signed-off-by: Ahmed Sayed <[email protected]>
No description provided.