i18n loading fixes.

This commit is contained in:
Steve 2018-12-10 08:42:23 +00:00
parent 5d2077395e
commit 5ed5b6b7c8
1 changed files with 18 additions and 15 deletions

View File

@ -19,16 +19,22 @@ Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
#include "i18n.h" #include "i18n.h"
static HashTable table; char *getTranslatedString(char *);
void setLanguage(char *, char *);
void cleanupLanguage(void);
static int hashCode(char *); static int hashCode(char *);
static void put(char *, char *); static void put(char *, char *);
static void initTable(void); static void initTable(void);
static HashTable table;
void setLanguage(char *applicationName, char *languageCode) void setLanguage(char *applicationName, char *languageCode)
{ {
char language[MAX_LINE_LENGTH], c[MAX_LINE_LENGTH]; char language[MAX_DESCRIPTION_LENGTH], c[MAX_LINE_LENGTH];
char *lang, **key, **value; char **key, **value;
#ifndef _WIN32
char *lang;
#endif
int i, swap; int i, swap;
FILE *fp; FILE *fp;
MOHeader header; MOHeader header;
@ -48,7 +54,7 @@ void setLanguage(char *applicationName, char *languageCode)
if (c[0] != '\0') if (c[0] != '\0')
{ {
STRNCPY(language, c, MAX_LINE_LENGTH); STRNCPY(language, c, MAX_DESCRIPTION_LENGTH);
GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, c, MAX_LINE_LENGTH); GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, c, MAX_LINE_LENGTH);
@ -62,26 +68,21 @@ void setLanguage(char *applicationName, char *languageCode)
#else #else
if ((lang = getenv("LC_ALL")) || (lang = getenv("LC_CTYPE")) || (lang = getenv("LANG"))) if ((lang = getenv("LC_ALL")) || (lang = getenv("LC_CTYPE")) || (lang = getenv("LANG")))
{ {
STRNCPY(language, lang, MAX_LINE_LENGTH); STRNCPY(language, lang, MAX_DESCRIPTION_LENGTH);
} }
#endif #endif
} }
else else
{ {
STRNCPY(language, languageCode, MAX_LINE_LENGTH); STRNCPY(language, languageCode, MAX_DESCRIPTION_LENGTH);
} }
strtok(language, "."); strtok(language, ".");
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Locale is %s", language); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Locale is %s", language);
sprintf(c, "locale/%s.mo", language); sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName);
if (!fileExists(c))
{
sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName);
}
#if DEV == 1 #if DEV == 1
printf("Opening %s\n", c); printf("Opening %s\n", c);
@ -102,6 +103,8 @@ void setLanguage(char *applicationName, char *languageCode)
strtok(language, "_"); strtok(language, "_");
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Language is %s", language);
sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName); sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName);
#if DEV == 1 #if DEV == 1