Created
May 16, 2013 10:52
-
-
Save stianl/5590899 to your computer and use it in GitHub Desktop.
Debugging language detection in Play framework on Heroku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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