Return best loaded language code in LoadLanguageCommand. (#2232)
Closes #2227.
This commit is contained in:
parent
391c728a16
commit
cc5498a42a
@ -95,10 +95,12 @@ public class LoadLanguageCommand extends Command {
|
||||
}
|
||||
|
||||
ObjectNode translations = null;
|
||||
String bestLang = null;
|
||||
for (int i = langs.length-1; i >= 0; i--) {
|
||||
if (langs[i] == null) continue;
|
||||
ObjectNode json = loadLanguage(this.servlet, modname, langs[i]);
|
||||
if (json != null) {
|
||||
bestLang = langs[i];
|
||||
if (translations == null) {
|
||||
translations = json;
|
||||
} else {
|
||||
@ -111,7 +113,7 @@ public class LoadLanguageCommand extends Command {
|
||||
try {
|
||||
ObjectNode node = ParsingUtilities.mapper.createObjectNode();
|
||||
node.put("dictionary", translations);
|
||||
node.put("lang", new TextNode(langs[0]));
|
||||
node.put("lang", new TextNode(bestLang));
|
||||
respondJSON(response, node);
|
||||
} catch (IOException e) {
|
||||
logger.error("Error writing language labels to response stream");
|
||||
|
@ -58,9 +58,20 @@ public class LoadLanguageCommandTests extends CommandTestBase {
|
||||
|
||||
JsonNode response = ParsingUtilities.mapper.readValue(writer.toString(), JsonNode.class);
|
||||
assertTrue(response.has("dictionary"));
|
||||
assertEquals(response.get("lang").asText(), "foobar");
|
||||
assertEquals(response.get("lang").asText(), "en");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadNoLanguage() throws JsonParseException, JsonMappingException, IOException, ServletException {
|
||||
when(request.getParameter("module")).thenReturn("core");
|
||||
when(request.getParameter("lang")).thenReturn("");
|
||||
|
||||
command.doPost(request, response);
|
||||
|
||||
JsonNode response = ParsingUtilities.mapper.readValue(writer.toString(), JsonNode.class);
|
||||
assertTrue(response.has("dictionary"));
|
||||
assertEquals(response.get("lang").asText(), "en");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLanguageFallback() throws JsonParseException, JsonMappingException, IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user