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

Use browser locale for floating point numbers formatted String.format() in UI #857

Conversation

a-sayyed
Copy link
Contributor

No description provided.

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()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

@schabdo schabdo added this to the 0.3.0M5 milestone Jul 1, 2019
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();
Copy link
Contributor

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...

Copy link
Contributor

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Remove this initialization to "null", the compiler will do that for you. rule

* List of available localizations
*/
private List<String> availableLocals = Collections.singletonList("en");
public Localization(final List<Resource> locales) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Document this public constructor by adding an explicit description. rule

@hawkbit-bot
Copy link

SonarQube analysis reported 2 issues

  • MINOR 2 minor

Watch the comments in this conversation to review them.

@a-sayyed a-sayyed force-pushed the feature/add_locale_to_String_format branch from 0c569a0 to 033dcf0 Compare July 9, 2019 11:28
* localization files (message.properties) as resources
*/
public UiProperties(@Value("classpath*:messages_*.properties") final Resource[] localesResources) {
this.localization = new Localization(Arrays.asList(localesResources));
Copy link
Contributor Author

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()));
Copy link
Contributor Author

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?

Copy link
Contributor

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.

@schabdo schabdo modified the milestones: 0.3.0M5, 0.3.0M6 Jul 29, 2019
return new Locale(localizationProperties.getDefaultLocal());
return localizationProperties.getDefaultLocal() == null
? desiredLocale
: localizationProperties.getDefaultLocal();
Copy link
Contributor

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()));
Copy link
Contributor

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;
Copy link
Contributor

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?

@laverman
Copy link
Contributor

@a-sayyed please check the commit history, if all commits have a 'signed-off' to it

@a-sayyed a-sayyed force-pushed the feature/add_locale_to_String_format branch from d917985 to 7d59344 Compare August 28, 2019 08:32
@a-sayyed a-sayyed changed the title added Locale.ENGLISH to String.format() for numbers with floating point use browser Locale in String.format() in UI for numbers with floating point Aug 30, 2019
@stefbehl stefbehl merged commit a85dafa into eclipse-hawkbit:master Sep 2, 2019
@stefbehl stefbehl deleted the feature/add_locale_to_String_format branch September 2, 2019 06:45
@schabdo schabdo changed the title use browser Locale in String.format() in UI for numbers with floating point Use browser locale for floating point numbers formatted String.format() in UI Jan 16, 2020
AmmarBikic pushed a commit to bosch-io/hawkbit that referenced this pull request Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants