From 152149133732a45a13f3c8ab728de767536a09ab Mon Sep 17 00:00:00 2001 From: Ales Kozumplik Date: Wed, 5 Oct 2011 13:58:37 +0200 Subject: Handle strange lang boot argument values. First, internally translate '.utf8' to '.UTF-8' so it matches the lang-table. Second, if a language missing from the lang-table is used with lang=, fallback on en_US. Resolves: rhbz#731356 --- loader/lang.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'loader/lang.c') diff --git a/loader/lang.c b/loader/lang.c index 6b1fa8e4f..a11de14f3 100644 --- a/loader/lang.c +++ b/loader/lang.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "loader.h" #include "lang.h" @@ -103,6 +104,14 @@ char * translateString(char * str) { static struct langInfo * languages = NULL; static int numLanguages = 0; +static int defaultLanguageIndex(void) { + int i; + for (i = 0; i < numLanguages; ++i) + if (!strcmp(languages[i].lc_all, LANG_DEFAULT)) + return i; + return -1; +} + static void loadLanguageList(void) { char * file = "/etc/lang-table"; FILE * f; @@ -144,6 +153,25 @@ int getLangInfo(struct langInfo ** langs) { return numLanguages; } +/** + * Normalize the value of lang= boot argument. + * + * Currently only replaces the trailing .utf8 with .UTF-8. + * + * Returns a heap-allocated string. + */ +gchar *normalizeLang(const gchar *s) +{ + if (g_str_has_suffix(s, ".utf8")) { + gchar *lang = g_strndup(s, strlen(s) - strlen(".utf8")); + gchar *result = g_strconcat(lang, ".UTF-8", NULL); + g_free(lang); + return result; + } + + return g_strdup(s); +} + void loadLanguage(void) { char *filename; @@ -395,8 +423,9 @@ int setLanguage (const char * key, int forced) { } } - logMessage(ERROR, "unable to set to requested language %s", key); - return -1; + logMessage(ERROR, "unable to set the requested language '%s', " + "setting the default '%s'", key, LANG_DEFAULT); + return setupLanguage(defaultLanguageIndex(), forced | !FL_KICKSTART(flags)); } int chooseLanguage(char ** lang) { -- cgit