@Test public void testThatWeCanRetrieveJsonBundlesUsedByI18Next() throws Exception { Action.ActionResult result = Action.action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.getBundleResourceForI18Next("fr en dev", null); } }).invoke(); final ObjectNode json = json(result); System.out.println(json); assertThat(json.get("fr")).isNotNull(); assertThat(json.get("fr").get("translation")).isNotNull(); assertThat(json.get("fr").get("translation").get("welcome").asText()).isEqualToIgnoringCase("bonjour"); assertThat(json.get("fr").get("translation").get("app").get("title").asText()).contains("Mon"); assertThat(json.get("dev")).isNotNull(); assertThat(json.get("dev").get("translation")).isNotNull(); assertThat(json.get("dev").get("translation").get("welcome").asText()).isEqualToIgnoringCase("hello"); assertThat(json.get("dev").get("translation").get("app").get("title").asText()).contains("My"); }
@Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") public Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { List<Locale> locales = new ArrayList<>(); if (!Strings.isNullOrEmpty(listOfLocales)) { String[] items = listOfLocales.split(" "); for (String item : items) { if ("dev".equalsIgnoreCase(item)) { locales.add(InternationalizationService.DEFAULT_LOCALE); } else { locales.add(Locale.forLanguageTag(item)); } } } String etag; StringBuilder builder = new StringBuilder(); for (Locale locale : locales) { builder.append(service.etag(locale)); } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } ObjectNode result = json.newObject(); for (Locale locale : locales) { ObjectNode lang = json.newObject(); ObjectNode translation = json.newObject(); lang.set("translation", translation); Collection<ResourceBundle> bundles = service.bundles(locale); for (ResourceBundle bundle : bundles) { for (String key : bundle.keySet()) { populateJsonResourceBundle(translation, key, bundle.getString(key)); } } String langName = locale.toLanguageTag(); if (locale.equals(InternationalizationService.DEFAULT_LOCALE)) { langName = "dev"; } result.set(langName, lang); } return ok(result).with(HeaderNames.ETAG, etag); }
I18nController extends DefaultController { @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") public Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { List<Locale> locales = new ArrayList<>(); if (!Strings.isNullOrEmpty(listOfLocales)) { String[] items = listOfLocales.split(" "); for (String item : items) { if ("dev".equalsIgnoreCase(item)) { locales.add(InternationalizationService.DEFAULT_LOCALE); } else { locales.add(Locale.forLanguageTag(item)); } } } String etag; StringBuilder builder = new StringBuilder(); for (Locale locale : locales) { builder.append(service.etag(locale)); } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } ObjectNode result = json.newObject(); for (Locale locale : locales) { ObjectNode lang = json.newObject(); ObjectNode translation = json.newObject(); lang.set("translation", translation); Collection<ResourceBundle> bundles = service.bundles(locale); for (ResourceBundle bundle : bundles) { for (String key : bundle.keySet()) { populateJsonResourceBundle(translation, key, bundle.getString(key)); } } String langName = locale.toLanguageTag(); if (locale.equals(InternationalizationService.DEFAULT_LOCALE)) { langName = "dev"; } result.set(langName, lang); } return ok(result).with(HeaderNames.ETAG, etag); } }
I18nController extends DefaultController { @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") public Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { List<Locale> locales = new ArrayList<>(); if (!Strings.isNullOrEmpty(listOfLocales)) { String[] items = listOfLocales.split(" "); for (String item : items) { if ("dev".equalsIgnoreCase(item)) { locales.add(InternationalizationService.DEFAULT_LOCALE); } else { locales.add(Locale.forLanguageTag(item)); } } } String etag; StringBuilder builder = new StringBuilder(); for (Locale locale : locales) { builder.append(service.etag(locale)); } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } ObjectNode result = json.newObject(); for (Locale locale : locales) { ObjectNode lang = json.newObject(); ObjectNode translation = json.newObject(); lang.set("translation", translation); Collection<ResourceBundle> bundles = service.bundles(locale); for (ResourceBundle bundle : bundles) { for (String key : bundle.keySet()) { populateJsonResourceBundle(translation, key, bundle.getString(key)); } } String langName = locale.toLanguageTag(); if (locale.equals(InternationalizationService.DEFAULT_LOCALE)) { langName = "dev"; } result.set(langName, lang); } return ok(result).with(HeaderNames.ETAG, etag); }  }
I18nController extends DefaultController { @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") public Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { List<Locale> locales = new ArrayList<>(); if (!Strings.isNullOrEmpty(listOfLocales)) { String[] items = listOfLocales.split(" "); for (String item : items) { if ("dev".equalsIgnoreCase(item)) { locales.add(InternationalizationService.DEFAULT_LOCALE); } else { locales.add(Locale.forLanguageTag(item)); } } } String etag; StringBuilder builder = new StringBuilder(); for (Locale locale : locales) { builder.append(service.etag(locale)); } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } ObjectNode result = json.newObject(); for (Locale locale : locales) { ObjectNode lang = json.newObject(); ObjectNode translation = json.newObject(); lang.set("translation", translation); Collection<ResourceBundle> bundles = service.bundles(locale); for (ResourceBundle bundle : bundles) { for (String key : bundle.keySet()) { populateJsonResourceBundle(translation, key, bundle.getString(key)); } } String langName = locale.toLanguageTag(); if (locale.equals(InternationalizationService.DEFAULT_LOCALE)) { langName = "dev"; } result.set(langName, lang); } return ok(result).with(HeaderNames.ETAG, etag); }  @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.properties") Result getBundleResource(@PathParameter("file") String file,
                                    @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales,
                                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); @Route(method = HttpMethod.GET, uri = "i18n/{key}") Result getMessage(@Parameter("key") String key, @QueryParameter("locale") Locale locale); @Route(method = HttpMethod.GET, uri = "i18n") Result getMessages(@QueryParameter("locales") List<Locale> locales,
                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); }
I18nController extends DefaultController { @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") public Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { List<Locale> locales = new ArrayList<>(); if (!Strings.isNullOrEmpty(listOfLocales)) { String[] items = listOfLocales.split(" "); for (String item : items) { if ("dev".equalsIgnoreCase(item)) { locales.add(InternationalizationService.DEFAULT_LOCALE); } else { locales.add(Locale.forLanguageTag(item)); } } } String etag; StringBuilder builder = new StringBuilder(); for (Locale locale : locales) { builder.append(service.etag(locale)); } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } ObjectNode result = json.newObject(); for (Locale locale : locales) { ObjectNode lang = json.newObject(); ObjectNode translation = json.newObject(); lang.set("translation", translation); Collection<ResourceBundle> bundles = service.bundles(locale); for (ResourceBundle bundle : bundles) { for (String key : bundle.keySet()) { populateJsonResourceBundle(translation, key, bundle.getString(key)); } } String langName = locale.toLanguageTag(); if (locale.equals(InternationalizationService.DEFAULT_LOCALE)) { langName = "dev"; } result.set(langName, lang); } return ok(result).with(HeaderNames.ETAG, etag); }  @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.properties") Result getBundleResource(@PathParameter("file") String file,
                                    @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales,
                                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); @Route(method = HttpMethod.GET, uri = "i18n/{key}") Result getMessage(@Parameter("key") String key, @QueryParameter("locale") Locale locale); @Route(method = HttpMethod.GET, uri = "i18n") Result getMessages(@QueryParameter("locales") List<Locale> locales,
                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch);  }