Added localization to String.format (#857)
Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com>
This commit is contained in:
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -53,7 +54,6 @@ public class UiProperties implements Serializable {
|
||||
this.fixedTimeZone = fixedTimeZone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Localization information
|
||||
*/
|
||||
@@ -63,26 +63,26 @@ public class UiProperties implements Serializable {
|
||||
/**
|
||||
* Default localization
|
||||
*/
|
||||
private String defaultLocal = "en";
|
||||
private Locale defaultLocal = Locale.ENGLISH;
|
||||
|
||||
/**
|
||||
* List of available localizations
|
||||
*/
|
||||
private List<String> availableLocals = Collections.singletonList("en");
|
||||
private List<Locale> availableLocals = Collections.singletonList(Locale.ENGLISH);
|
||||
|
||||
public String getDefaultLocal() {
|
||||
public Locale getDefaultLocal() {
|
||||
return defaultLocal;
|
||||
}
|
||||
|
||||
public List<String> getAvailableLocals() {
|
||||
public List<Locale> getAvailableLocals() {
|
||||
return availableLocals;
|
||||
}
|
||||
|
||||
public void setDefaultLocal(final String defaultLocal) {
|
||||
public void setDefaultLocal(final Locale defaultLocal) {
|
||||
this.defaultLocal = defaultLocal;
|
||||
}
|
||||
|
||||
public void setAvailableLocals(final List<String> availableLocals) {
|
||||
public void setAvailableLocals(final List<Locale> availableLocals) {
|
||||
this.availableLocals = availableLocals;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.rollout;
|
||||
|
||||
import java.util.Locale;
|
||||
import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.getCurrentLocale;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -154,9 +155,7 @@ public final class DistributionBarHelper {
|
||||
final double minTotalSize = MINIMUM_PART_SIZE * noOfParts;
|
||||
final double availableSize = PARENT_SIZE_IN_PCT - minTotalSize;
|
||||
final double val = MINIMUM_PART_SIZE + (double) value / totalValue * availableSize;
|
||||
// necessary due the format must contain a dot and other locals might
|
||||
// use a comma
|
||||
return String.format(Locale.ENGLISH, "%.3f", val) + "%";
|
||||
return String.format(getCurrentLocale(), "%.3f", val) + "%";
|
||||
}
|
||||
|
||||
private static String getPart(final int partIndex, final Status status, final Long value, final Long totalValue,
|
||||
|
||||
@@ -478,7 +478,7 @@ public final class HawkbitCommonUtil {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return String.format("%.1f", tmpFinishedPercentage);
|
||||
return String.format(getCurrentLocale(), "%.1f", tmpFinishedPercentage);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,14 +574,14 @@ public final class HawkbitCommonUtil {
|
||||
*/
|
||||
public static Locale getLocaleToBeUsed(final UiProperties.Localization localizationProperties,
|
||||
final Locale desiredLocale) {
|
||||
final List<String> availableLocals = localizationProperties.getAvailableLocals();
|
||||
final List<Locale> availableLocals = localizationProperties.getAvailableLocals();
|
||||
// ckeck if language code of UI locale matches an available local.
|
||||
// Country, region and variant are ignored. "availableLocals" must only
|
||||
// contain language codes without country or other extensions.
|
||||
if (availableLocals.contains(desiredLocale.getLanguage())) {
|
||||
if (availableLocals.contains(desiredLocale)) {
|
||||
return desiredLocale;
|
||||
}
|
||||
return new Locale(localizationProperties.getDefaultLocal());
|
||||
return localizationProperties.getDefaultLocal();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user