Browse Source

Fix locale for macOS-style locales

(cherry picked from commit 1e7f078ce9832a1b53be587d1d4cfbd14b760623)
Damon 8 years ago
parent
commit
e3be51f87c
1 changed files with 12 additions and 6 deletions
  1. 12 6
      core/translation.cpp

+ 12 - 6
core/translation.cpp

@@ -844,8 +844,11 @@ void Translation::_set_messages(const DVector<String>& p_messages){
 
 void Translation::set_locale(const String& p_locale) {
 
-	if(!is_valid_locale(p_locale)) {
-		String trimmed_locale = get_trimmed_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));
@@ -853,7 +856,7 @@ void Translation::set_locale(const String& p_locale) {
 		locale=trimmed_locale;
 	}
 	else {
-		locale=p_locale;
+		locale=univ_locale;
 	}
 }
 
@@ -919,8 +922,11 @@ Translation::Translation() {
 
 void TranslationServer::set_locale(const String& p_locale) {
 
-	if(!is_valid_locale(p_locale)) {
-		String trimmed_locale = get_trimmed_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));
@@ -928,7 +934,7 @@ void TranslationServer::set_locale(const String& p_locale) {
 		locale=trimmed_locale;
 	}
 	else {
-		locale=p_locale;
+		locale=univ_locale;
 	}
 }