diff options
Diffstat (limited to 'android')
-rw-r--r-- | android/ui/base/l10n/l10n_util.cc | 16 | ||||
-rw-r--r-- | android/ui/base/l10n/l10n_util.h | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/android/ui/base/l10n/l10n_util.cc b/android/ui/base/l10n/l10n_util.cc index 649b86e..93217be 100644 --- a/android/ui/base/l10n/l10n_util.cc +++ b/android/ui/base/l10n/l10n_util.cc @@ -94,4 +94,20 @@ string16 GetStringFUTF16(int message_id, const string16& a, const string16& b, c return ReplaceStringPlaceholders(str, replacements, NULL); } +std::string GetApplicationLocale() +{ + JNIEnv* env = android::GetJNIEnv(); + jclass locale_class = env->FindClass("java/util/Locale"); + jmethodID get_default_locale = env->GetStaticMethodID(locale_class, "getDefault", "()Ljava/util/Locale;"); + jmethodID to_string = env->GetMethodID(locale_class, "toString", "()Ljava/lang/String;"); + jobject locale_jobj = env->CallStaticObjectMethod(locale_class, get_default_locale); + jstring locale_jstr = static_cast<jstring>(env->CallObjectMethod(locale_jobj, to_string)); + std::string locale = android::JstringToStdString(env, locale_jstr); + env->DeleteLocalRef(locale_jstr); + env->DeleteLocalRef(locale_jobj); + env->DeleteLocalRef(locale_class); + + return locale; +} + } diff --git a/android/ui/base/l10n/l10n_util.h b/android/ui/base/l10n/l10n_util.h index 9c14f55..248f49f 100644 --- a/android/ui/base/l10n/l10n_util.h +++ b/android/ui/base/l10n/l10n_util.h @@ -94,5 +94,6 @@ namespace l10n_util { string16 GetStringUTF16(int message_id); string16 GetStringFUTF16(int message_id, const string16& a, const string16& b, const string16& c); +std::string GetApplicationLocale(); } #endif |