summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamon Myers <damon.shane.myers@gmail.com>2016-10-27 03:36:32 -0500
committerRémi Verschelde <remi@verschelde.fr>2016-10-27 10:36:32 +0200
commit470ead74dbc3d6ea7133ab90c0d09ed637e7a5f5 (patch)
treebf6d7ad1869a0d33aed0fe09bf6a41665f9c5e63
parent6f09841e24e98183b893c2346ec20bc6593438e8 (diff)
downloadredot-engine-470ead74dbc3d6ea7133ab90c0d09ed637e7a5f5.tar.gz
Change set_locale to fallback to the global language (#6910)
-rw-r--r--core/translation.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/core/translation.cpp b/core/translation.cpp
index 4592d00598..0137db3b42 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,17 @@ 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;
+ if(!is_valid_locale(p_locale)) {
+ String trimmed_locale = get_trimmed_locale(p_locale);
+
+ ERR_EXPLAIN("Invalid Locale: "+trimmed_locale);
+ ERR_FAIL_COND(!is_valid_locale(trimmed_locale));
+
+ locale=trimmed_locale;
+ }
+ else {
+ locale=p_locale;
+ }
}
void Translation::add_message( const StringName& p_src_text, const StringName& p_xlated_text ) {
@@ -906,9 +919,17 @@ 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;
+ if(!is_valid_locale(p_locale)) {
+ String trimmed_locale = get_trimmed_locale(p_locale);
+
+ ERR_EXPLAIN("Invalid Locale: "+trimmed_locale);
+ ERR_FAIL_COND(!is_valid_locale(trimmed_locale));
+
+ locale=trimmed_locale;
+ }
+ else {
+ locale=p_locale;
+ }
}
String TranslationServer::get_locale() const {