KEYCLOAK-10826: Provide the locale name in the LocaleBean to be used in themes
This commit is contained in:
parent
6d6db1f3e5
commit
1d2d6591b2
1 changed files with 15 additions and 3 deletions
|
@ -30,16 +30,18 @@ import java.util.Properties;
|
|||
public class LocaleBean {
|
||||
|
||||
private String current;
|
||||
private String currentLanguageTag;
|
||||
private List<Locale> supported;
|
||||
|
||||
public LocaleBean(RealmModel realm, java.util.Locale current, UriBuilder uriBuilder, Properties messages) {
|
||||
this.current = messages.getProperty("locale_" + current.toLanguageTag(), current.toLanguageTag());
|
||||
this.currentLanguageTag = current.toLanguageTag();
|
||||
this.current = messages.getProperty("locale_" + this.currentLanguageTag, this.currentLanguageTag);
|
||||
|
||||
supported = new LinkedList<>();
|
||||
for (String l : realm.getSupportedLocales()) {
|
||||
String label = messages.getProperty("locale_" + l, l);
|
||||
String url = uriBuilder.replaceQueryParam("kc_locale", l).build().toString();
|
||||
supported.add(new Locale(label, url));
|
||||
supported.add(new Locale(l, label, url));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,20 +49,30 @@ public class LocaleBean {
|
|||
return current;
|
||||
}
|
||||
|
||||
public String getCurrentLanguageTag() {
|
||||
return currentLanguageTag;
|
||||
}
|
||||
|
||||
public List<Locale> getSupported() {
|
||||
return supported;
|
||||
}
|
||||
|
||||
public static class Locale {
|
||||
|
||||
private String languageTag;
|
||||
private String label;
|
||||
private String url;
|
||||
|
||||
public Locale(String label, String url) {
|
||||
public Locale(String languageTag, String label, String url) {
|
||||
this.languageTag = languageTag;
|
||||
this.label = label;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getLanguageTag() {
|
||||
return languageTag;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue