diff options
Diffstat (limited to 'core/translation.cpp')
-rw-r--r-- | core/translation.cpp | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/core/translation.cpp b/core/translation.cpp index 4592d00598..f368c9d5fc 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -292,6 +292,7 @@ static const char* locale_list[]={ "pa_PK", // Panjabi (Pakistan) "pl", // Polish "pl_PL", // Polish (Poland) +"pr", // Pirate "ps_AF", // Pushto (Afghanistan) "pt", // Portuguese "pt_BR", // Portuguese (Brazil) @@ -650,6 +651,7 @@ static const char* locale_names[]={ "Panjabi (Pakistan)", "Polish", "Polish (Poland)", +"Pirate", "Pushto (Afghanistan)", "Portuguese", "Portuguese (Brazil)", @@ -779,6 +781,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 +846,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 +924,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 { |