rt/emul/compact/src/main/java/java/util/Locale.java
changeset 1781 681e61714a1d
parent 1337 c794024954b5
child 1784 11679a57a895
     1.1 --- a/rt/emul/compact/src/main/java/java/util/Locale.java	Thu Oct 03 17:36:44 2013 +0200
     1.2 +++ b/rt/emul/compact/src/main/java/java/util/Locale.java	Sun Feb 22 09:00:14 2015 +0100
     1.3 @@ -45,6 +45,7 @@
     1.4  import java.io.ObjectOutputStream;
     1.5  import java.io.ObjectStreamField;
     1.6  import java.io.Serializable;
     1.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
     1.8  
     1.9  /**
    1.10   * A <code>Locale</code> object represents a specific geographical, political,
    1.11 @@ -634,8 +635,20 @@
    1.12       * @return the default locale for this instance of the Java Virtual Machine
    1.13       */
    1.14      public static Locale getDefault() {
    1.15 +        String lang = language();
    1.16 +        if (lang != null) {
    1.17 +            String[] arr = lang.split("-");
    1.18 +            return new Locale(arr[0], arr[1]);
    1.19 +        }
    1.20          return Locale.US;
    1.21      }
    1.22 +    
    1.23 +    @JavaScriptBody(args = {}, body = ""
    1.24 +        + "if (navigator.language) return navigator.language;\n"
    1.25 +        + "if (navigator.userLangage) return navigator.userLangage;\n"
    1.26 +        + "return null;\n"
    1.27 +    )
    1.28 +    private static native String language();
    1.29  
    1.30      /**
    1.31       * Gets the current value of the default locale for the specified Category
    1.32 @@ -654,7 +667,7 @@
    1.33       * @since 1.7
    1.34       */
    1.35      public static Locale getDefault(Locale.Category category) {
    1.36 -        return Locale.US;
    1.37 +        return getDefault();
    1.38      }
    1.39      
    1.40      /**