Skip to content

Commit

Permalink
Merge pull request #2242 from GluuFederation/oxtrust_2226
Browse files Browse the repository at this point in the history
feat: locale configurable
  • Loading branch information
yurem authored Sep 1, 2022
2 parents e7462eb + b0aff37 commit 9b64316
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
45 changes: 27 additions & 18 deletions server/src/main/java/org/gluu/oxtrust/LanguageBean.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.gluu.oxtrust;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
Expand All @@ -15,8 +14,9 @@
import org.gluu.oxtrust.model.GluuCustomAttribute;
import org.gluu.oxtrust.model.GluuCustomPerson;
import org.gluu.oxtrust.security.Identity;
import org.gluu.oxtrust.service.JsonConfigurationService;
import org.gluu.oxtrust.service.PersonService;
import org.gluu.util.StringHelper;
import org.gluu.model.LocaleSupported;

/**
* Created by eugeniuparvan on 3/6/17.
Expand All @@ -35,18 +35,23 @@ public class LanguageBean implements Serializable {

@Inject
private HomeAction homeAction;

@Inject
private JsonConfigurationService jsonConfigurationService;

private static Map<String, Object> countries;
private List<LocaleSupported> adminUiLocaleSupported;

static {
countries = new LinkedHashMap<String, Object>();
countries.put("English", Locale.ENGLISH); // label, value
countries.put("Russian", new Locale("ru"));
countries.put("French", new Locale("fr"));
}


public List<org.gluu.model.LocaleSupported> getCountriesInMap() {
adminUiLocaleSupported = jsonConfigurationService.getOxTrustappConfiguration().getAdminUiLocaleSupported();
if(adminUiLocaleSupported == null) {
adminUiLocaleSupported = new ArrayList<LocaleSupported>();
adminUiLocaleSupported.add(new LocaleSupported("en","English"));
}

return adminUiLocaleSupported;

public Map<String, Object> getCountriesInMap() {
return countries;
}

public String getLocaleCode() {
Expand Down Expand Up @@ -89,11 +94,7 @@ public void setLocaleCode(String localeCode) {

public void countryLocaleCodeChanged(ValueChangeEvent e) {
String newLocaleValue = e.getNewValue().toString();
for (Map.Entry<String, Object> entry : countries.entrySet()) {
if (entry.getValue().toString().equals(newLocaleValue)) {
FacesContext.getCurrentInstance().getViewRoot().setLocale((Locale) entry.getValue());
}
}
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale( newLocaleValue));
homeAction.init();
}

Expand All @@ -112,4 +113,12 @@ private void addLocale(GluuCustomPerson gluuCustomPerson, String localeCode) {
locale.setValue(localeCode);
gluuCustomPerson.getCustomAttributes().add(locale);
}

public List<org.gluu.model.LocaleSupported> getAdminUiLocaleSupported() {
return adminUiLocaleSupported;
}

public void setAdminUiLocaleSupported(List<org.gluu.model.LocaleSupported> adminUiLocaleSupported) {
this.adminUiLocaleSupported = adminUiLocaleSupported;
}
}
12 changes: 7 additions & 5 deletions server/src/main/webapp/WEB-INF/incl/layout/topmenu.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
<!-- Tasks: style can be found in dropdown.less -->
<li class="dropdown tasks-menu"><i
class="fa flag"></i> <span class="label">

<h:selectOneMenu style="margin-top:15px !important;"
value="#{language.localeCode}" onchange="submit()"
valueChangeListener="#{language.countryLocaleCodeChanged}">
<f:selectItems value="#{language.countriesInMap}" />
</h:selectOneMenu>
</span>
value="#{language.localeCode}" onchange="submit()"
valueChangeListener="#{language.countryLocaleCodeChanged}">
<f:selectItems value="#{language.getCountriesInMap()}" var="localeSupported"
itemValue="#{localeSupported.locale}" itemLabel="#{localeSupported.displayName}" />
</h:selectOneMenu>
</span>
</li>
<!-- User Account: style can be found in dropdown.less -->
<li class="dropdown user user-menu"><a href="#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@
"minLength": 1
}
},
"adminUiLocaleSupported" : {
"id": "adminUiLocaleSupported",
"description": "adminUiLocaleSupported.",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"additionalItems": true,
"items": {
"type": "object",
"additionalProperties": true,
"properties": {
"locale": {
"id": "locale",
"type": "string",
"minLength": 1
},
"displayName": {
"id": "displayName",
"type": "string",
"minLength": 1
}
}
}
},
"authMode": {
"id": "authMode",
"type": "string",
Expand Down

0 comments on commit 9b64316

Please sign in to comment.