-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/de/metas/ui/web/session/UserSessionLocale.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package de.metas.ui.web.session; | ||
|
||
import java.text.DecimalFormat; | ||
import java.text.DecimalFormatSymbols; | ||
|
||
import org.compiere.util.CCache; | ||
import org.compiere.util.DisplayType; | ||
|
||
import de.metas.i18n.Language; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
/* | ||
* #%L | ||
* metasfresh-webui-api | ||
* %% | ||
* Copyright (C) 2017 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-2.0.html>. | ||
* #L% | ||
*/ | ||
|
||
@Value | ||
public class UserSessionLocale | ||
{ | ||
public static final UserSessionLocale get(@NonNull final String adLanguage) | ||
{ | ||
return cache.getOrLoad(adLanguage, () -> new UserSessionLocale(adLanguage)); | ||
} | ||
|
||
private static final CCache<String, UserSessionLocale> cache = CCache.newCache(UserSessionLocale.class.getName(), 10, 0); | ||
|
||
private final String adLanguage; | ||
private final char numberDecimalSeparator; | ||
private final char numberGroupingSeparator; | ||
|
||
private UserSessionLocale(final String adLanguage) | ||
{ | ||
final Language language = Language.getLanguage(adLanguage); | ||
if (language == null) | ||
{ | ||
throw new IllegalArgumentException("No language found for " + adLanguage); | ||
} | ||
this.adLanguage = language.getAD_Language(); | ||
|
||
final DecimalFormat decimalFormat = DisplayType.getNumberFormat(DisplayType.Amount, language); | ||
final DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols(); | ||
numberDecimalSeparator = decimalFormatSymbols.getDecimalSeparator(); | ||
numberGroupingSeparator = decimalFormatSymbols.getGroupingSeparator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/de/metas/ui/web/session/json/JSONUserSessionLocale.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.metas.ui.web.session.json; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; | ||
|
||
import de.metas.ui.web.session.UserSessionLocale; | ||
import lombok.Value; | ||
|
||
/* | ||
* #%L | ||
* metasfresh-webui-api | ||
* %% | ||
* Copyright (C) 2017 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-2.0.html>. | ||
* #L% | ||
*/ | ||
|
||
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) | ||
@Value | ||
public class JSONUserSessionLocale | ||
{ | ||
public static JSONUserSessionLocale of(final UserSessionLocale locale) | ||
{ | ||
return new JSONUserSessionLocale(locale); | ||
} | ||
|
||
private final char numberDecimalSeparator; | ||
private final char numberGroupingSeparator; | ||
|
||
private JSONUserSessionLocale(final UserSessionLocale locale) | ||
{ | ||
numberDecimalSeparator = locale.getNumberDecimalSeparator(); | ||
numberGroupingSeparator = locale.getNumberGroupingSeparator(); | ||
} | ||
} |