Bug 1446202 - 1. Return correct locale string to Gecko; r=droeh

Locale.toString() doesn't return the correct locale format that Gecko
expects, so reformat the locale string before returning. (for example,
Locale.toString() returns "en_US_POSIX#Latn" whereas Gecko expects
"en-Latn-US-POSIX"). The incorrect locale format was preventing intl
code (and the datetime box) from initializing.

MozReview-Commit-ID: JmDYkDj31pL

--HG--
extra : rebase_source : 545e8f4e57e1e0086d3afb862c9dfa82ff89345f
This commit is contained in:
Jim Chen 2018-04-02 23:25:27 -04:00
Родитель 8f9f4aa5c1
Коммит b8e6f0675d
1 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -76,6 +76,7 @@ import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Looper;
@ -1872,6 +1873,21 @@ public class GeckoAppShell
@WrapForJNI
public static String getDefaultLocale() {
return Locale.getDefault().toString();
final Locale locale = Locale.getDefault();
if (Build.VERSION.SDK_INT >= 21) {
return locale.toLanguageTag();
}
final StringBuilder out = new StringBuilder(locale.getLanguage());
final String country = locale.getCountry();
final String variant = locale.getVariant();
if (!TextUtils.isEmpty(country)) {
out.append('-').append(country);
}
if (!TextUtils.isEmpty(variant)) {
out.append('-').append(variant);
}
// e.g. "en", "en-US", or "en-US-POSIX".
return out.toString();
}
}