GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1798297-locale-C 
into lp:widelands.

Commit message:
Fix fetching of translations when user locale is set to C. If the desired 
Widelands locale does not exist, try to fall back to en_US.utf8 to make libintl 
happy.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1798297 in widelands: "Language selection broken if locale is set to C"
  https://bugs.launchpad.net/widelands/+bug/1798297

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1798297-locale-C/+merge/358364
-- 
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/bug-1798297-locale-C into lp:widelands.
=== modified file 'src/base/i18n.cc'
--- src/base/i18n.cc	2018-08-12 06:47:11 +0000
+++ src/base/i18n.cc	2018-11-06 08:51:14 +0000
@@ -290,15 +290,26 @@
 		found = alt_str.find(',', 0);
 	}
 	if (leave_while) {
-		setenv("LANG", locale.c_str(), 1);
+		setenv("LC_ALL", locale.c_str(), 1);
+        setenv("LANG", locale.c_str(), 1);
 		setenv("LANGUAGE", locale.c_str(), 1);
 	} else {
-		log("No corresponding locale found - trying to set it via LANGUAGE=%s, LANG=%s\n",
-		    lang.c_str(), lang.c_str());
+		log("No corresponding locale found\n");
+        log(" - Set LANGUAGE, LANG and LC_ALL to '%s'\n",
+		    lang.c_str());
+
 		setenv("LANGUAGE", lang.c_str(), 1);
 		setenv("LANG", lang.c_str(), 1);
-		SETLOCALE(LC_MESSAGES, "");  // set locale according to the env. variables
-		                             // --> see  $ man 3 setlocale
+        setenv("LC_ALL", lang.c_str(), 1);
+
+        try {
+            SETLOCALE(LC_MESSAGES, "en_US.utf8");  // set locale according to the env. variables
+                                         // --> see  $ man 3 setlocale
+            log(" - Set system locale to 'en_US.utf8' to make '%s' accessible to libintl\n", lang.c_str());
+        } catch (std::exception&) {
+            SETLOCALE(LC_MESSAGES, "");  // set locale according to the env. variables
+                                         // --> see  $ man 3 setlocale
+        }
 		// assume that it worked
 		// maybe, do another check with the return value (?)
 		locale = lang;

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to