#include "config.h"#include "gettext.h"

Go to the source code of this file.
Classes | |
| struct | iLiad_locale_t |
Defines | |
| #define | _(String) gettext (String) |
| #define | DEFAULT_LOCALE "en_US" |
| #define | LOCALE_LIB_DIR "/usr/lib/locale" |
Functions | |
| guint | find_installed_locales (iLiad_locale_t **locale_installed_tbl) |
| void | free_installed_locales (iLiad_locale_t **locale_installed_tbl, gint locale_installed_num) |
| void | languagesInit () |
| #define _ | ( | String | ) | gettext (String) |
Definition at line 42 of file languages.h.
| #define DEFAULT_LOCALE "en_US" |
Definition at line 44 of file languages.h.
| #define LOCALE_LIB_DIR "/usr/lib/locale" |
Definition at line 45 of file languages.h.
| guint find_installed_locales | ( | iLiad_locale_t ** | locale_installed_tbl | ) |
Definition at line 96 of file languages.c.
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 // get locales currently installed 00113 dirp = opendir(LOCALE_LIB_DIR); 00114 if (dirp) 00115 { 00116 // count number of directory entries 00117 num = 0; 00118 while ((direntp = readdir(dirp)) != NULL) 00119 { 00120 num++; 00121 } 00122 00123 // allocate table for installed locales 00124 loc_locale_installed_tbl = g_new0(iLiad_locale_t, num); 00125 locale_installed_num = 0; 00126 00127 // get currently installed locales 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 // strip extension, if any 00139 cp = strchr(direntp->d_name, '.'); 00140 if (cp) 00141 { 00142 *cp = '\0'; 00143 } 00144 00145 // find locale in known locales 00146 for (locp = g_locale_known_tbl ; locp->code ; locp++) 00147 { 00148 if (strcmp(direntp->d_name, locp->code) == 0) 00149 { 00150 // found 00151 break; // exit for 00152 } 00153 } 00154 00155 // add this locale to installed locales 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 // sort installed locales on name 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 // return values 00183 ST_LOGPRINTF("Installed %d locales.", locale_installed_num); 00184 *locale_installed_tbl = loc_locale_installed_tbl; 00185 return locale_installed_num; 00186 }

| void free_installed_locales | ( | iLiad_locale_t ** | locale_installed_tbl, | |
| gint | locale_installed_num | |||
| ) |
Definition at line 188 of file languages.c.
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 ) ); // const_cast 00209 g_free( (gchar*)(locp->name ) ); // const_cast 00210 g_free( (gchar*)(locp->long_name) ); // const_cast 00211 } 00212 } 00213 00214 g_free(loc_locale_installed_tbl); 00215 *locale_installed_tbl = NULL; 00216 }
| void languagesInit | ( | ) |
init the language/localisation settings
| none |
Definition at line 218 of file languages.c.
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 // default is english 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 }

1.5.6