Add support for 3-letter language code in android
This commit is contained in:
parent
987558bf66
commit
641dbcf9c0
@ -524,5 +524,24 @@ public class SuperTuxKartActivity extends SDLActivity
|
||||
public int getKeyboardHeight() { return m_keyboard_height.get(); }
|
||||
// ------------------------------------------------------------------------
|
||||
public int getMovedHeight() { return m_moved_height.get(); }
|
||||
// ------------------------------------------------------------------------
|
||||
public String getLocaleString()
|
||||
{
|
||||
String language = "";
|
||||
if (mCurrentLocale != null)
|
||||
{
|
||||
language = mCurrentLocale.getLanguage();
|
||||
if (language == "iw")
|
||||
language = "he";
|
||||
else if (language == "in")
|
||||
language = "id";
|
||||
else if (language == "ji")
|
||||
language = "yi";
|
||||
String country = mCurrentLocale.getCountry();
|
||||
if (country != "")
|
||||
language += "_" + country;
|
||||
}
|
||||
return language;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,11 @@
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
#ifdef MOBILE_STK
|
||||
#ifdef ANDROID
|
||||
#include <jni.h>
|
||||
#include "utils/utf8/unchecked.h"
|
||||
#include "SDL_system.h"
|
||||
#elif defined(MOBILE_STK)
|
||||
#include "SDL_locale.h"
|
||||
#endif
|
||||
|
||||
@ -369,6 +373,72 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
|
||||
language = (char*)&languageStr;
|
||||
language = StringUtils::findAndReplace(language, "-", "_");
|
||||
}
|
||||
#elif defined(ANDROID)
|
||||
JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
|
||||
jobject native_activity = NULL;
|
||||
jclass class_native_activity = NULL;
|
||||
jmethodID method_id = NULL;
|
||||
jstring text = NULL;
|
||||
if (env == NULL)
|
||||
{
|
||||
Log::error("Translation",
|
||||
"constructor is unable to SDL_AndroidGetJNIEnv.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
native_activity = (jobject)SDL_AndroidGetActivity();
|
||||
if (native_activity == NULL)
|
||||
{
|
||||
Log::error("Translation",
|
||||
"constructor is unable to SDL_AndroidGetActivity.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
class_native_activity = env->GetObjectClass(native_activity);
|
||||
if (class_native_activity == NULL)
|
||||
{
|
||||
Log::error("Translation",
|
||||
"constructor is unable to find object class.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
method_id = env->GetMethodID(class_native_activity,
|
||||
"getLocaleString", "()Ljava/lang/String;");
|
||||
if (method_id == NULL)
|
||||
{
|
||||
Log::error("Translation",
|
||||
"constructor is unable to find method id.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
text =
|
||||
(jstring)env->CallObjectMethod(native_activity, method_id);
|
||||
if (text == NULL)
|
||||
{
|
||||
Log::error("Translation",
|
||||
"Failed to CallObjectMethod for constructor.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
if (text != NULL)
|
||||
{
|
||||
const uint16_t* utf16_text =
|
||||
(const uint16_t*)env->GetStringChars(text, NULL);
|
||||
if (utf16_text != NULL)
|
||||
{
|
||||
const size_t str_len = env->GetStringLength(text);
|
||||
utf8::unchecked::utf16to8(
|
||||
utf16_text, utf16_text + str_len,
|
||||
std::back_inserter(language));
|
||||
env->ReleaseStringChars(text, utf16_text);
|
||||
}
|
||||
env->DeleteLocalRef(text);
|
||||
}
|
||||
if (class_native_activity != NULL)
|
||||
env->DeleteLocalRef(class_native_activity);
|
||||
if (native_activity != NULL)
|
||||
env->DeleteLocalRef(native_activity);
|
||||
#elif defined(MOBILE_STK)
|
||||
SDL_Locale* locale = SDL_GetPreferredLocales();
|
||||
if (locale)
|
||||
|
Loading…
Reference in New Issue
Block a user