00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026
00027
00028
00029
00030
00031 #include "config.h"
00032 #include <locale.h>
00033 #include <sys/types.h>
00034 #include <dirent.h>
00035 #include <sys/stat.h>
00036 #include <unistd.h>
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040
00041 #include <glib.h>
00042
00043 #include <liberregxml/erregapi.h>
00044
00045 #include "contentListerLog.h"
00046 #include "gettext.h"
00047 #include "languages.h"
00048
00049 static gchar *g_szUserLanguage = NULL;
00050
00051
00052
00053
00054
00055
00056 gboolean languageSelected(void)
00057 {
00058 gboolean ret = FALSE;
00059 struct stat statbuf;
00060 char* cp;
00061
00062 CL_LOGPRINTF("entry");
00063
00064 cp = g_strdup_printf(LOCALE_LIB_DIR "/%s", g_szUserLanguage);
00065 if ( stat(cp, &statbuf) == 0
00066 && S_ISDIR(statbuf.st_mode) )
00067 {
00068 ret = TRUE;
00069 }
00070 g_free(cp);
00071
00072 return ret;
00073 }
00074
00075 void languagesInit()
00076 {
00077 char *result;
00078 regUserSetting_t *theUserSetting = NULL;
00079
00080 #if ENABLE_NLS
00081 CL_LOGPRINTF("ENABLE_NLS = TRUE");
00082 #else
00083 CL_LOGPRINTF("ENABLE_NLS = FALSE");
00084 #endif
00085
00086
00087 g_free(g_szUserLanguage);
00088 theUserSetting = erRegGetUserSetting();
00089 if (theUserSetting)
00090 {
00091 CL_LOGPRINTF("Using LOCALE: %s\n", theUserSetting->language);
00092 setlocale(LC_ALL, theUserSetting->language);
00093 g_setenv("LANG", theUserSetting->language, 1);
00094 g_szUserLanguage = g_strdup(theUserSetting->language);
00095 erRegFreeUserSetting(theUserSetting);
00096 }
00097 else
00098 {
00099
00100 CL_WARNPRINTF("Using default LOCALE: %s\n", DEFAULT_LOCALE);
00101 setlocale(LC_ALL, DEFAULT_LOCALE);
00102 g_setenv("LANG", DEFAULT_LOCALE, 1);
00103 g_szUserLanguage = g_strdup(DEFAULT_LOCALE);
00104 }
00105
00106 textdomain(PACKAGE);
00107
00108 CL_LOGPRINTF("LOCALE_DIR: %s", LOCALE_DIR);
00109 CL_LOGPRINTF("PACKAGE: %s", PACKAGE);
00110
00111 result = bindtextdomain(PACKAGE, LOCALE_DIR);;
00112
00113 CL_LOGPRINTF("bindtextdomain: %s", result);
00114
00115 textdomain(PACKAGE);
00116 }
00117
00118 const gchar *languagesGetLocale()
00119 {
00120 return g_szUserLanguage ? g_szUserLanguage : DEFAULT_LOCALE;
00121 }
00122
00123 const gchar *languagesGetCountry()
00124 {
00125 static gchar *country = NULL;
00126 char *cp;
00127
00128 g_free(country);
00129 country = g_strdup(g_szUserLanguage);
00130
00131 cp = strchr(country, '_');
00132 if (cp != NULL)
00133 {
00134 *cp = '\0';
00135 }
00136
00137 return country;
00138 }
00139
00140 const gchar *languagesGetDefaultCountry()
00141 {
00142 static gchar *country = NULL;
00143 char *cp;
00144
00145 g_free(country);
00146 country = g_strdup(DEFAULT_LOCALE);
00147
00148 cp = strchr(country, '_');
00149 if (cp != NULL)
00150 {
00151 *cp = '\0';
00152 }
00153
00154 return country;
00155 }