diff options
author | Darkvater <darkvater@openttd.org> | 2006-03-25 09:22:10 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2006-03-25 09:22:10 +0000 |
commit | 9b5d8a9921d0f8a0ed5b9dd0f3d796a35c342f8c (patch) | |
tree | 86d8ae1e4f41e2d9e2ecfe600c9e0bcd66d31b18 /strings.c | |
parent | 6cafd5f0e33f44818cc128ad3b1a140a3215e853 (diff) | |
download | openttd-9b5d8a9921d0f8a0ed5b9dd0f3d796a35c342f8c.tar.xz |
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
- CodeChange: Change the function GetCurrentLocale(). It returns the locale from some default environment-variables, plus a custom one defined as parameter. If all fail, it tries $LANG.
Diffstat (limited to 'strings.c')
-rw-r--r-- | strings.c | 41 |
1 files changed, 26 insertions, 15 deletions
@@ -1051,6 +1051,30 @@ bool ReadLanguagePack(int lang_index) return true; } +/** Determine the current charset based on the environment + * First check some default values, after this one we passed ourselves + * and if none exist return the value for $LANG + * @param environment variable to check conditionally if default ones are not + * set. Pass NULL if you don't want additional checks. + * @return return string containing current charset, or NULL if not-determinable */ +const char *GetCurrentLocale(const char *param) +{ + const char *env; + + env = getenv("LANGUAGE"); + if (env != NULL) return env; + + env = getenv("LC_ALL"); + if (env != NULL) return env; + + if (param != NULL) { + env = getenv(param); + if (env != NULL) return env; + } + + return getenv("LANG"); +} + // make a list of the available language packs. put the data in _dynlang struct. void InitializeLanguagePacks(void) { @@ -1063,24 +1087,11 @@ void InitializeLanguagePacks(void) 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; - } - } + const char *env = GetCurrentLocale("LC_MESSAGES"); + if (env != NULL) snprintf(lang, lengthof(lang), "%.2s", env); n = GetLanguageList(files, lengthof(files)); def = -1; |