summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-08-01 01:12:21 +0000
committertron <tron@openttd.org>2005-08-01 01:12:21 +0000
commit0226e0799d4491ed6a6c76ed7c980de68d37ee2c (patch)
tree49fb6265221e9b4f193ca07cec1d906f70448bee
parent49c399fa8303fc154b017b281dd4b015db0fc5d3 (diff)
downloadopenttd-0226e0799d4491ed6a6c76ed7c980de68d37ee2c.tar.xz
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
-rw-r--r--strings.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/strings.c b/strings.c
index e1b05ad8a..eb361fdcc 100644
--- a/strings.c
+++ b/strings.c
@@ -1084,13 +1084,32 @@ void InitializeLanguagePacks(void)
int n;
int m;
int def;
+ int fallback;
LanguagePack hdr;
FILE *in;
char *files[32];
+ uint j;
+
+ char lang[] = "en";
+ static const char* env[] = {
+ "LANGUAGE",
+ "LC_ALL",
+ "LC_MESSAGES",
+ "LANG"
+ };
+
+ for (j = 0; j < lengthof(env); j++) {
+ const char* envlang = getenv(env[j]);
+ if (envlang != NULL) {
+ snprintf(lang, lengthof(lang), "%.2s", envlang);
+ break;
+ }
+ }
n = GetLanguageList(files, lengthof(files));
- def = 0; // default language file
+ def = -1;
+ fallback = 0;
// go through the language files and make sure that they are valid.
for (i = m = 0; i != n; i++) {
@@ -1110,10 +1129,12 @@ void InitializeLanguagePacks(void)
dl->ent[m].file = files[i];
dl->ent[m].name = strdup(hdr.name);
- if (strcmp(hdr.name, "English") == 0) def = m;
+ if (strcmp(hdr.name, "English") == 0) fallback = m;
+ if (strcmp(hdr.isocode, lang) == 0) def = m;
m++;
}
+ if (def == -1) def = fallback;
if (m == 0)
error(n == 0 ? "No available language packs" : "Invalid version of language packs");