set fallback locale to English, ultimate fall through is to return the code string itself
parent
285ad71874
commit
2abcd96bbe
|
@ -3,7 +3,7 @@
|
|||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"%>
|
||||
|
||||
<spring:message code="home.welcome" var="title"/>
|
||||
<spring:message code="home.title" var="title"/>
|
||||
<o:header title="${title}" />
|
||||
<o:topbar pageName="Home" />
|
||||
<div class="container-fluid main">
|
||||
|
|
|
@ -363,5 +363,13 @@
|
|||
"number_clients": "Authorized clients: <span class=\"label label-info\" id=\"clientCount\">{0}</span>",
|
||||
"number_approvals": "Approved sites: <span class=\"label label-info\" id=\"approvalCount\">{0}</span>"
|
||||
}
|
||||
},
|
||||
"topbar": {
|
||||
"about": "About",
|
||||
"contact": "Contact",
|
||||
"statistics": "Statistics",
|
||||
"home": "Home",
|
||||
"login": "Log in",
|
||||
"logout": "Log out"
|
||||
}
|
||||
}
|
|
@ -47,6 +47,8 @@ public class JsonMessageSource extends AbstractMessageSource {
|
|||
private static final Logger logger = LoggerFactory.getLogger(JsonMessageSource.class);
|
||||
|
||||
private Resource baseDirectory;
|
||||
|
||||
private Locale fallbackLocale = new Locale("en"); // US English is the fallback language
|
||||
|
||||
private Map<Locale, JsonObject> languageMaps = new HashMap<>();
|
||||
|
||||
|
@ -55,9 +57,20 @@ public class JsonMessageSource extends AbstractMessageSource {
|
|||
|
||||
JsonObject lang = getLanguageMap(locale);
|
||||
|
||||
MessageFormat mf = getMessageFormat(code, locale, lang);
|
||||
String value = getValue(code, lang);
|
||||
|
||||
if (value == null) {
|
||||
// if we haven't found anything, try the default locale
|
||||
lang = getLanguageMap(fallbackLocale);
|
||||
value = getValue(code, lang);
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
value = code;
|
||||
}
|
||||
|
||||
MessageFormat mf = new MessageFormat(value, locale);
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
return mf;
|
||||
}
|
||||
|
||||
|
@ -67,14 +80,19 @@ public class JsonMessageSource extends AbstractMessageSource {
|
|||
* @param lang
|
||||
* @return
|
||||
*/
|
||||
private MessageFormat getMessageFormat(String code, Locale locale, JsonObject lang) {
|
||||
private String getValue(String code, JsonObject lang) {
|
||||
|
||||
// if there's no language map, nothing to look up
|
||||
if (lang == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JsonElement e = lang;
|
||||
|
||||
Iterable<String> parts = Splitter.on('.').split(code);
|
||||
Iterator<String> it = parts.iterator();
|
||||
|
||||
String value = code;
|
||||
String value = null;
|
||||
|
||||
while (it.hasNext()) {
|
||||
String p = it.next();
|
||||
|
@ -99,9 +117,8 @@ public class JsonMessageSource extends AbstractMessageSource {
|
|||
}
|
||||
|
||||
|
||||
MessageFormat mf = new MessageFormat(value, locale);
|
||||
return value;
|
||||
|
||||
return mf;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue