Permalink
Browse files

Merge pull request #371 from srenault/java/messages

Fallback to System Locale when no request available in the scope
  • Loading branch information...
2 parents 80fddb7 + fffd4b3 commit 4ae84cd4fb0f13e56e5db58a4859a1cfad85b928 @pk11 pk11 committed Jun 22, 2012
Showing with 10 additions and 2 deletions.
  1. +10 −2 framework/src/play/src/main/java/play/i18n/Messages.java
@@ -3,6 +3,8 @@
import scala.collection.mutable.Buffer;
import java.util.Arrays;
+import java.util.Locale;
+import play.api.i18n.Lang;
/**
* High-level internationalisation API.
@@ -35,7 +37,13 @@ public static String get(Lang lang, String key, Object... args) {
*/
public static String get(String key, Object... args) {
Buffer<Object> scalaArgs = scala.collection.JavaConverters.asScalaBufferConverter(Arrays.asList(args)).asScala();
- return play.api.i18n.Messages.apply(key, scalaArgs, play.mvc.Http.Context.current().lang());
+ Lang lang = null;
+ if(play.mvc.Http.Context.current.get() != null) {
+ lang = play.mvc.Http.Context.current().lang();
+ } else {
+ Locale defaultLocale = Locale.getDefault();
+ lang = new Lang(defaultLocale.getLanguage(), defaultLocale.getCountry());
+ }
+ return play.api.i18n.Messages.apply(key, scalaArgs, lang);
}
-
}

0 comments on commit 4ae84cd

Please sign in to comment.