[android] Correct ReplaceDeprecatedLanguageCode implementation. Take into account in_ID codes.

This commit is contained in:
vng 2015-07-07 17:10:28 +03:00 committed by Alex Zolotarev
parent a02bc0c646
commit 258ad592dd
3 changed files with 22 additions and 21 deletions

View file

@ -210,7 +210,7 @@ Java_com_mapswithme_maps_search_SearchFragment_nativeRunSearch(
search::SearchParams params;
params.m_query = jni::ToNativeString(env, s);
params.SetInputLocale(ReplaceDeprecatedLanguageCode(env, jni::ToNativeString(env, lang)));
params.SetInputLocale(ReplaceDeprecatedLanguageCode(jni::ToNativeString(env, lang)));
/// @note These magic numbers should be equal with NOT_FIRST_QUERY and HAS_POSITION
/// from SearchFragment.java
@ -305,7 +305,7 @@ Java_com_mapswithme_maps_search_SearchFragment_runInteractiveSearch(JNIEnv * env
{
search::SearchParams params;
params.m_query = jni::ToNativeString(env, query);
params.SetInputLocale(ReplaceDeprecatedLanguageCode(env, jni::ToNativeString(env, lang)));
params.SetInputLocale(ReplaceDeprecatedLanguageCode(jni::ToNativeString(env, lang)));
g_framework->NativeFramework()->StartInteractiveSearch(params);
}

View file

@ -1,16 +1,32 @@
#include "Language.hpp"
#include "../core/jni_helper.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#include "base/string_utils.hpp"
#include "std/string.hpp"
static char const * DEFAULT_LANG = "en";
string ReplaceDeprecatedLanguageCode(string const & lang)
{
// in* -> id
// iw* -> he
if (strings::StartsWith(lang, "in"))
return "id";
else if (strings::StartsWith(lang, "iw"))
return "he";
return lang;
}
/// This function is called from native c++ code
string GetAndroidSystemLanguage()
{
static char const * DEFAULT_LANG = "en";
JNIEnv * env = jni::GetEnv();
if (!env)
{
@ -49,6 +65,5 @@ string GetAndroidSystemLanguage()
if (res.empty())
res = DEFAULT_LANG;
LOG(LDEBUG, ("System language:", res));
return res;
return ReplaceDeprecatedLanguageCode(res);
}

View file

@ -4,19 +4,5 @@
#include "std/string.hpp"
/// more details about deprecated language codes http://developer.android.com/reference/java/util/Locale.html
inline string ReplaceDeprecatedLanguageCode(JNIEnv * env, string const language)
{
/// correct language codes & deprecated ones to be replaced
static constexpr char * INDONESIAN_LANG_DEPRECATED = "in";
static constexpr char * INDONESIAN_LANG = "id";
static constexpr char * HEBREW_LANG_DEPRECATED = "iw";
static constexpr char * HEBREW_LANG = "he";
if (!language.compare(INDONESIAN_LANG_DEPRECATED))
return INDONESIAN_LANG;
else if (!language.compare(HEBREW_LANG_DEPRECATED))
return HEBREW_LANG;
return language;
}
/// More details about deprecated language codes http://developer.android.com/reference/java/util/Locale.html
string ReplaceDeprecatedLanguageCode(string const & language);