diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-10-30 09:00:45 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-10-30 09:00:45 -0300 |
commit | ab4126f51061277e87b41c48b40e7b54942d4eca (patch) | |
tree | c58168b60323c4d43b58743b099e562a89e60a56 /core/translation.cpp | |
parent | 8b15b26eedad4fdd33d50f5f9aa0fcc1875d503f (diff) | |
parent | 914015f3b63dd956e72ea937d46ea4b2db005ada (diff) |
Merge branch 'master' of https://github.com/godotengine/godot
Diffstat (limited to 'core/translation.cpp')
-rw-r--r-- | core/translation.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/core/translation.cpp b/core/translation.cpp index 4592d00598..4d81073fe6 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -779,6 +779,11 @@ Vector<String> TranslationServer::get_all_locale_names(){ } +static String get_trimmed_locale(const String& p_locale) { + + return p_locale.substr(0,2); +} + static bool is_valid_locale(const String& p_locale) { const char **ptr=locale_list; @@ -839,9 +844,20 @@ void Translation::_set_messages(const DVector<String>& p_messages){ void Translation::set_locale(const String& p_locale) { - ERR_EXPLAIN("Invalid Locale: "+p_locale); - ERR_FAIL_COND(!is_valid_locale(p_locale)); - locale=p_locale; + // replaces '-' with '_' for macOS Sierra-style locales + String univ_locale = p_locale.replace("-", "_"); + + if(!is_valid_locale(univ_locale)) { + String trimmed_locale = get_trimmed_locale(univ_locale); + + ERR_EXPLAIN("Invalid Locale: "+trimmed_locale); + ERR_FAIL_COND(!is_valid_locale(trimmed_locale)); + + locale=trimmed_locale; + } + else { + locale=univ_locale; + } } void Translation::add_message( const StringName& p_src_text, const StringName& p_xlated_text ) { @@ -906,9 +922,20 @@ Translation::Translation() { void TranslationServer::set_locale(const String& p_locale) { - ERR_EXPLAIN("Invalid Locale: "+p_locale); - ERR_FAIL_COND(!is_valid_locale(p_locale)); - locale=p_locale; + // replaces '-' with '_' for macOS Sierra-style locales + String univ_locale = p_locale.replace("-", "_"); + + if(!is_valid_locale(univ_locale)) { + String trimmed_locale = get_trimmed_locale(univ_locale); + + ERR_EXPLAIN("Invalid Locale: "+trimmed_locale); + ERR_FAIL_COND(!is_valid_locale(trimmed_locale)); + + locale=trimmed_locale; + } + else { + locale=univ_locale; + } } String TranslationServer::get_locale() const { |