00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00028 #include "config.h"
00029 #include <locale.h>
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include <sys/types.h>
00033 #include <dirent.h>
00034 #include <sys/stat.h>
00035 #include <unistd.h>
00036 #include <stdlib.h>
00037
00038 #include <glib.h>
00039 #include <gtk/gtk.h>
00040
00041 #include <libergtk/ergtk.h>
00042
00043 #include "setupLog.h"
00044 #include "gettext.h"
00045 #include "languages.h"
00046 #include "iLiadConfigData.h"
00047
00048
00049
00050 static const iLiad_locale_t g_locale_known_tbl[] = {
00051 { "en_US", "English" , "Set English as the language for your iLiad" },
00052 { "de_DE", "Deutsch" , "Ich möchte Deutsch als Sprache des iLiad" },
00053 { "es_ES", "Español" , "Seleccionar el idioma Español para su iLiad" },
00054 { "fr_FR", "Français" , "Employer le français comme langue de votre iLiad" },
00055 { "it_IT", "Italiano" , "Scegli italiano come lingua per il tuo iLiad" },
00056 { "nl_NL", "Nederlands" , "Kies Nederlands als taal voor uw iLiad" },
00057 { "no_NO", "Norsk" , "Set Norwegian as the language for your iLiad" },
00058 { "pl_PL", "Polski" , "Set Polish as the language for your iLiad" },
00059 { "pt_PT", "Português" , "Seleccionar Português como língua do seu iLiad" },
00060 { "ru_RU", "Русский" , "Set Russian as the language for your iLiad" },
00061 { "fi_FI", "Suomi" , "Set Finnish as the language for your iLiad" },
00062 { "sv_SE", "Svenska" , "Sätt svenska som språk för din iLiad" },
00063 { "zh_CN", "中文" , "设置中文为iLiad的默认语言" },
00064 { "ja_JP", "日本語" , "Set Japanese as the language for your iLiad" },
00065 { "ko_KR", "한국어" , "Set Korean as the language for your iLiad" },
00066 { NULL, NULL , NULL }
00067 };
00068
00069 static int locale_cmp(const void *left, const void *right)
00070 {
00071 const iLiad_locale_t *locp;
00072 const gchar *left_name = ((iLiad_locale_t*)left )->name;
00073 const gchar *right_name = ((iLiad_locale_t*)right)->name;
00074
00075 gint pos;
00076 gint left_pos = 9999;
00077 gint right_pos = 9999;
00078
00079 pos = 0;
00080 for (locp = g_locale_known_tbl ; locp->code ; locp++)
00081 {
00082 if (strcmp(left_name, locp->name) == 0)
00083 {
00084 left_pos = pos;
00085 }
00086 if (strcmp(right_name, locp->name) == 0)
00087 {
00088 right_pos = pos;
00089 }
00090 pos++;
00091 }
00092
00093 return left_pos - right_pos;
00094 }
00095
00096 guint find_installed_locales(iLiad_locale_t** locale_installed_tbl)
00097 {
00098 ST_LOGPRINTF("entry");
00099
00100 int num;
00101 DIR *dirp;
00102 struct dirent *direntp;
00103 struct stat statbuf;
00104 char *cp;
00105 int i;
00106
00107 const iLiad_locale_t *locp;
00108
00109 int locale_installed_num = 0;
00110 iLiad_locale_t* loc_locale_installed_tbl= NULL;
00111
00112
00113 dirp = opendir(LOCALE_LIB_DIR);
00114 if (dirp)
00115 {
00116
00117 num = 0;
00118 while ((direntp = readdir(dirp)) != NULL)
00119 {
00120 num++;
00121 }
00122
00123
00124 loc_locale_installed_tbl = g_new0(iLiad_locale_t, num);
00125 locale_installed_num = 0;
00126
00127
00128 rewinddir(dirp);
00129 while ((direntp = readdir(dirp)) != NULL)
00130 {
00131 cp = g_strdup_printf(LOCALE_LIB_DIR "/%s", direntp->d_name);
00132 i = stat(cp, &statbuf);
00133 g_free(cp);
00134 if ( i == 0
00135 && S_ISDIR(statbuf.st_mode)
00136 && direntp->d_name[0] != '.' )
00137 {
00138
00139 cp = strchr(direntp->d_name, '.');
00140 if (cp)
00141 {
00142 *cp = '\0';
00143 }
00144
00145
00146 for (locp = g_locale_known_tbl ; locp->code ; locp++)
00147 {
00148 if (strcmp(direntp->d_name, locp->code) == 0)
00149 {
00150
00151 break;
00152 }
00153 }
00154
00155
00156 if (locp->code)
00157 {
00158 loc_locale_installed_tbl[locale_installed_num].code = g_strdup(locp->code );
00159 loc_locale_installed_tbl[locale_installed_num].name = g_strdup(locp->name );
00160 loc_locale_installed_tbl[locale_installed_num].long_name = g_strdup(locp->long_name);
00161 locale_installed_num++;
00162 }
00163 else
00164 {
00165 loc_locale_installed_tbl[locale_installed_num].code = g_strdup(direntp->d_name);
00166 loc_locale_installed_tbl[locale_installed_num].name = g_strdup(direntp->d_name);
00167 loc_locale_installed_tbl[locale_installed_num].long_name = g_strdup(direntp->d_name);
00168 locale_installed_num++;
00169 }
00170 }
00171 }
00172
00173
00174 qsort( loc_locale_installed_tbl,
00175 locale_installed_num,
00176 sizeof(loc_locale_installed_tbl[0]),
00177 locale_cmp );
00178
00179 closedir(dirp);
00180 }
00181
00182
00183 ST_LOGPRINTF("Installed %d locales.", locale_installed_num);
00184 *locale_installed_tbl = loc_locale_installed_tbl;
00185 return locale_installed_num;
00186 }
00187
00188 void free_installed_locales(iLiad_locale_t** locale_installed_tbl, gint locale_installed_num)
00189 {
00190 ST_LOGPRINTF("entry [%d]", locale_installed_num);
00191 gint i;
00192 iLiad_locale_t* locp;
00193 iLiad_locale_t* loc_locale_installed_tbl;
00194
00195 g_return_if_fail(locale_installed_tbl != NULL);
00196 g_return_if_fail(locale_installed_num > 0);
00197
00198 loc_locale_installed_tbl = *locale_installed_tbl;
00199 g_return_if_fail(loc_locale_installed_tbl != NULL);
00200
00201 for (i = 0; i < locale_installed_num; i++)
00202 {
00203 locp = &loc_locale_installed_tbl[i];
00204 ST_LOGPRINTF("locp [%d] [%p]", i, locp);
00205 if (locp)
00206 {
00207 ST_LOGPRINTF("%s, %s", locp->code, locp->name);
00208 g_free( (gchar*)(locp->code ) );
00209 g_free( (gchar*)(locp->name ) );
00210 g_free( (gchar*)(locp->long_name) );
00211 }
00212 }
00213
00214 g_free(loc_locale_installed_tbl);
00215 *locale_installed_tbl = NULL;
00216 }
00217
00218 void languagesInit()
00219 {
00220 char *result;
00221 char *theLanguage;
00222
00223 #if ENABLE_NLS
00224 ST_LANGUAGEPRINTF("ENABLE_NLS = TRUE");
00225 #else
00226 ST_LANGUAGEPRINTF("ENABLE_NLS = FALSE");
00227 #endif
00228
00229 theLanguage = iLiad_config_data_get_language();
00230 if ( theLanguage == NULL
00231 || theLanguage[0] == '\0' )
00232 {
00233
00234 theLanguage = DEFAULT_LOCALE;
00235 }
00236
00237 setlocale(LC_ALL, theLanguage);
00238 g_setenv("LANG", theLanguage, 1);
00239
00240 textdomain(PACKAGE);
00241
00242 ST_LANGUAGEPRINTF("Language: [%s]", theLanguage);
00243 ST_LANGUAGEPRINTF("LOCALE_DIR: [%s]", LOCALE_DIR);
00244 ST_LANGUAGEPRINTF("PACKAGE: [%s]", PACKAGE);
00245
00246 result = bindtextdomain(PACKAGE, LOCALE_DIR);;
00247
00248 ST_LANGUAGEPRINTF("bindtextdomain: [%s]", result);
00249
00250 textdomain(PACKAGE);
00251 }
00252
00253