Skip to content

Instantly share code, notes, and snippets.

@stianl
Created May 16, 2013 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stianl/5590899 to your computer and use it in GitHub Desktop.
Save stianl/5590899 to your computer and use it in GitHub Desktop.
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");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment