Debugging language detection in Play framework on Heroku
public static Result acceptedLanguages() throws IOException {
Map<String, Object> stuff = new HashMap<>();
stuff.put("profilepage.profile.button.connect", Messages.get("profilepage.profile.button.connect"));
stuff.put("acceptedLanguages header", request().headers().containsKey("Accept-Language")?request().headers().get("Accept-Language")[0]:"non-existant");
stuff.put("play.mvc.Http.Context.current().request().cookies()", Http.Context.current().request().cookies());
List<Lang> availables = Lang.availables();
Collection<Locale> transform = Collections2.transform(availables, new Function<Lang, Locale>() {
@Override
public Locale apply(Lang lang) {
return lang.toLocale();
}
});
stuff.put("play.i18n.Lang.availables() to locales", transform);
stuff.put("play.mvc.Http.Context.current().request().headers()", play.mvc.Http.Context.current().request().headers());
stuff.put("play.mvc.Http.Context.current.get()", play.mvc.Http.Context.current.get());
stuff.put("play.mvc.Http.Context.current().lang()", play.mvc.Http.Context.current().lang());
stuff.put("play.mvc.Http.Context.current().lang().toLocale()", play.mvc.Http.Context.current().lang().toLocale());
List<Lang> value = request().acceptLanguages();
Collection<Locale> locales = Collections2.transform(value, new Function<Lang, Locale>() {
@Override
public Locale apply(@Nullable Lang lang) {
if (lang == null)
return null;
return lang.toLocale();
}
});
stuff.put("acceptedLanguages to locale", locales);
ObjectMapper mapper = new ObjectMapper( );
mapper.configure( SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false );
return ok(mapper.writeValueAsString(stuff)).as("application/json");
}