IDEMPIERE-2297 Use browser default language instead of Client System's / based on patch from Nicolas Micoud (nmicoud)
This commit is contained in:
parent
1fabfda6d6
commit
fad1554e3f
|
@ -189,20 +189,26 @@ public class LoginPanel extends Window implements EventListener<Event>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make the default language the language of client System
|
// Make the default language the browser language; otherwise it will be the language of client System
|
||||||
// TODO: possible improvement to check if the first default browser language is supported and default to it
|
List<String> browserLanguages = browserLanguages(Executions.getCurrent().getHeader("accept-language"));
|
||||||
// Executions.getCurrent().getHeader("accept-language");
|
String defaultSystemLanguage = MClient.get(ctx, 0).getAD_Language();
|
||||||
String defaultLanguage = MClient.get(ctx, 0).getAD_Language();
|
if (!browserLanguages.contains(defaultSystemLanguage))
|
||||||
for(int i = 0; i < lstLanguage.getItemCount(); i++)
|
browserLanguages.add(defaultSystemLanguage);
|
||||||
{
|
boolean found = false;
|
||||||
|
for (String browserLanguage : browserLanguages) {
|
||||||
|
for (int i = 0; i < lstLanguage.getItemCount(); i++) {
|
||||||
Comboitem li = lstLanguage.getItemAtIndex(i);
|
Comboitem li = lstLanguage.getItemAtIndex(i);
|
||||||
if (li.getValue().equals(defaultLanguage))
|
String lang = li.getValue();
|
||||||
{
|
if (lang.startsWith(browserLanguage)) {
|
||||||
lstLanguage.setSelectedIndex(i);
|
lstLanguage.setSelectedIndex(i);
|
||||||
languageChanged(li.getLabel());
|
languageChanged(li.getLabel());
|
||||||
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (found)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createUI() {
|
protected void createUI() {
|
||||||
|
@ -654,4 +660,31 @@ public class LoginPanel extends Window implements EventListener<Event>
|
||||||
|
|
||||||
wndLogin.resetPassword(userId, users.size() == 0);
|
wndLogin.resetPassword(userId, users.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** get default languages from the browser */
|
||||||
|
private List<String> browserLanguages(String header) {
|
||||||
|
List<String> arrstr = new ArrayList<String>();
|
||||||
|
for (String str : header.split(",")){
|
||||||
|
String[] arr = str.trim().replace("-", "_").split(";");
|
||||||
|
|
||||||
|
for (String s : arr){
|
||||||
|
s = s.trim();
|
||||||
|
if (!s.startsWith("q=")) {
|
||||||
|
if (s.contains("_") && s.length() == 5) {
|
||||||
|
String baselang = s.substring(0, 2).toLowerCase();
|
||||||
|
StringBuffer lang = new StringBuffer(baselang).append("_").append(s.substring(3).toUpperCase());
|
||||||
|
if (!arrstr.contains(lang.toString()))
|
||||||
|
arrstr.add(lang.toString());
|
||||||
|
if (!arrstr.contains(baselang))
|
||||||
|
arrstr.add(baselang);
|
||||||
|
} else {
|
||||||
|
if (s.length() == 2 && !arrstr.contains(s.toLowerCase()))
|
||||||
|
arrstr.add(s.toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arrstr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue