summaryrefslogtreecommitdiffstats
path: root/loader2/lang.c
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2002-12-17 17:46:49 +0000
committerJeremy Katz <katzj@redhat.com>2002-12-17 17:46:49 +0000
commit0c51730003901d756e688f8281bbeeb4d42aaf9b (patch)
treeba78faf6f7222027d9cd5d7cbcc0db46272029df /loader2/lang.c
parenta46c0c55d17e48fbc099d8eb0812a3ef24808afd (diff)
downloadanaconda-0c51730003901d756e688f8281bbeeb4d42aaf9b.tar.gz
anaconda-0c51730003901d756e688f8281bbeeb4d42aaf9b.tar.xz
anaconda-0c51730003901d756e688f8281bbeeb4d42aaf9b.zip
regularlize language names so that for (eg) en_US.UTF-8, you can specify
lang en lang en_US lang en_US.UTF-8 and have any of them work. this keeps kickstart configs from breaking
Diffstat (limited to 'loader2/lang.c')
-rw-r--r--loader2/lang.c89
1 files changed, 79 insertions, 10 deletions
diff --git a/loader2/lang.c b/loader2/lang.c
index b8d08bb03..a7dc6b72a 100644
--- a/loader2/lang.c
+++ b/loader2/lang.c
@@ -198,23 +198,92 @@ void loadLanguage (char * file, int flags) {
}
+/* give the index of the language to set to -- sets the appropriate
+ * lang variables if we have a font.
+ *
+ * ASSUMPTION: languages exists
+ */
+static void setLangEnv (int i, int flags) {
+ if (i > numLanguages)
+ return;
+
+ logMessage("setting language to %s", languages[i].lc_all);
+ if (!strcmp(languages[i].font, "None"))
+ return;
+
+ setenv("LANG", languages[i].lc_all, 1);
+ setenv("LANGKEY", languages[i].key, 1);
+ setenv("LC_ALL", languages[i].lc_all, 1);
+ setenv("LINGUAS", languages[i].lc_all, 1);
+ loadLanguage (NULL, flags);
+}
+
+/* this is pretty simple. we want to break down the language specifier
+ * into its short form (eg, en_US)
+ */
+static char * getLangShortForm(char * oldLang) {
+ char * lang;
+ char * c;
+
+ lang = strdup(oldLang);
+
+ c = strchr(lang, '@');
+ if (c) {
+ *c = '\0';
+ }
+
+ c = strchr(lang, '.');
+ if (c) {
+ *c = '\0';
+ }
+
+ return lang;
+}
+
+/* return the nick of a language -- eg en_US -> en */
+static char * getLangNick(char * oldLang) {
+ char * lang;
+ char * c;
+
+ lang = strdup(oldLang);
+
+ c = strchr(lang, '_');
+ if (c) {
+ *c = '\0';
+ }
+
+ return lang;
+}
+
void setLanguage (char * key, int flags) {
int i;
if (!languages) loadLanguageList(flags);
for (i = 0; i < numLanguages; i++) {
- if (!strcmp(languages[i].key, key)) {
- if (!strcmp(languages[i].font, "None"))
- break;
- setenv("LANG", languages[i].lc_all, 1);
- setenv("LANGKEY", languages[i].key, 1);
- setenv("LC_ALL", languages[i].lc_all, 1);
- setenv("LINGUAS", languages[i].lc_all, 1);
- loadLanguage (NULL, flags);
- break;
+ if (!strcmp(languages[i].lc_all, key)) {
+ setLangEnv(i, flags);
+ return;
+ }
+ }
+
+ /* we didn't specify anything that's exactly in the lang-table. check
+ * against short forms and nicks */
+ for (i = 0; i < numLanguages; i++) {
+ if (!strcmp(getLangShortForm(languages[i].lc_all), key)) {
+ setLangEnv(i, flags);
+ return;
+ }
+ }
+
+ for (i = 0; i < numLanguages; i++) {
+ if (!strcmp(getLangNick(languages[i].lc_all), key)) {
+ setLangEnv(i, flags);
+ return;
}
}
+
+ logMessage("unable to set to requested language %s", key);
}
/* returns 0 on success, 1 on failure */
@@ -299,7 +368,7 @@ int chooseLanguage(char ** lang, int flags) {
languages[choice].lang);
return 0;
}
- setLanguage (languages[choice].key, flags);
+ setLanguage (languages[choice].lc_all, flags);
/* clear out top line */
buf = alloca(80);