return table;
}
+static char *__get_string_before(const char *str, const char *delim)
+{
+ char *new_str;
+ char *dup_str;
+ char *token;
+
+ dup_str = strdup(str);
+ if (dup_str == NULL)
+ return NULL;
+
+ token = strtok(dup_str, delim);
+ if (token == NULL) {
+ free(dup_str);
+ return NULL;
+ }
+
+ new_str = strdup(token);
+ free(dup_str);
+
+ return new_str;
+}
+
static GList *__append_langs(const char *lang, GList *list, GHashTable *table)
{
GList *child_list;
GList *child_iter;
GList *found;
char *child_lang;
- char *dup_lang;
- char *token;
+ char *parent_lang;
+ char *extract_lang;
+ char *tmp;
if (lang == NULL)
return list;
found = g_list_find_custom(g_list_first(list), lang,
__compare_langs);
if (found) {
- list = g_list_remove_link(list, found);
- free(found->data);
- g_list_free(found);
- list = g_list_append(list, strdup(lang));
+ tmp = (char *)found->data;
+ list = g_list_remove(list, tmp);
+ list = g_list_append(list, tmp);
return list;
}
- dup_lang = strdup(lang);
- if (dup_lang == NULL)
+ extract_lang = __get_string_before(lang, ".");
+ if (extract_lang == NULL)
return list;
- token = strtok(dup_lang, "_");
- if (token == NULL) {
- free(dup_lang);
+ parent_lang = __get_string_before(extract_lang, "_");
+ if (parent_lang == NULL) {
+ free(extract_lang);
return list;
}
- child_list = g_hash_table_lookup(table, token);
+ child_list = g_hash_table_lookup(table, parent_lang);
if (child_list == NULL) {
- free(dup_lang);
+ free(parent_lang);
+ free(extract_lang);
return list;
}
found = g_list_find_custom(g_list_first(child_list),
- lang, __compare_langs);
+ extract_lang, __compare_langs);
if (found) {
- list = g_list_append(list, strdup(lang));
- child_list = g_list_remove_link(child_list, found);
- free(found->data);
- g_list_free(found);
- free(dup_lang);
+ tmp = (char *)found->data;
+ child_list = g_list_remove(child_list, tmp);
+ list = g_list_append(list, tmp);
+ free(parent_lang);
+ free(extract_lang);
return list;
}
+ free(extract_lang);
found = g_list_find_custom(g_list_first(child_list),
- token, __compare_langs);
+ parent_lang, __compare_langs);
if (found) {
- list = g_list_append(list, strdup(token));
- child_list = g_list_remove_link(child_list, found);
- free(found->data);
- g_list_free(found);
- free(dup_lang);
+ tmp = (char *)found->data;
+ child_list = g_list_remove(child_list, tmp);
+ list = g_list_append(list, tmp);
+ free(parent_lang);
return list;
}
- free(dup_lang);
+ free(parent_lang);
child_iter = g_list_first(child_list);
while (child_iter) {
return list;
}
+static GList *__append_default_langs(GList *list)
+{
+ const char *langs[] = {"en_US", "en_GB", "en"};
+ unsigned int i;
+ GList *found;
+
+ for (i = 0; i < (sizeof(langs) / sizeof(langs[0])); i++) {
+ found = g_list_find_custom(g_list_first(list), langs[i],
+ __compare_langs);
+ if (found == NULL)
+ list = g_list_append(list, strdup(langs[i]));
+ }
+
+ return list;
+}
+
static char *__get_language(const char *lang)
{
GHashTable *table;
g_list_free_full(list, free);
g_hash_table_destroy(table);
+ lang_list = __append_default_langs(lang_list);
iter = g_list_first(lang_list);
while (iter) {
language = (char *)iter->data;
}
g_list_free_full(lang_list, free);
- n = sizeof(buf) - strlen(buf) - 1;
- strncat(buf, ":", n);
- n = sizeof(buf) - strlen(buf) - 1;
- strncat(buf, "en_US:en_GB:en", n);
-
return strdup(buf);
}
return table;
}
+static char *__get_string_before(const char *str, const char *delim)
+{
+ char *new_str;
+ char *dup_str;
+ char *token;
+
+ dup_str = strdup(str);
+ if (dup_str == NULL)
+ return NULL;
+
+ token = strtok(dup_str, delim);
+ if (token == NULL) {
+ free(dup_str);
+ return NULL;
+ }
+
+ new_str = strdup(token);
+ free(dup_str);
+
+ return new_str;
+}
+
static GList *__append_langs(const char *lang, GList *list, GHashTable *table)
{
GList *child_list;
GList *child_iter;
GList *found;
char *child_lang;
- char *dup_lang;
- char *token;
+ char *parent_lang;
+ char *extract_lang;
+ char *tmp;
if (lang == NULL)
return list;
found = g_list_find_custom(g_list_first(list), lang,
__compare_langs);
if (found) {
- list = g_list_remove_link(list, found);
- free(found->data);
- g_list_free(found);
- list = g_list_append(list, strdup(lang));
+ tmp = (char *)found->data;
+ list = g_list_remove(list, tmp);
+ list = g_list_append(list, tmp);
return list;
}
- dup_lang = strdup(lang);
- if (dup_lang == NULL)
+ extract_lang = __get_string_before(lang, ".");
+ if (extract_lang == NULL)
return list;
- token = strtok(dup_lang, "_");
- if (token == NULL) {
- free(dup_lang);
+ parent_lang = __get_string_before(extract_lang, "_");
+ if (parent_lang == NULL) {
+ free(extract_lang);
return list;
}
- child_list = g_hash_table_lookup(table, token);
+ child_list = g_hash_table_lookup(table, parent_lang);
if (child_list == NULL) {
- free(dup_lang);
+ free(parent_lang);
+ free(extract_lang);
return list;
}
found = g_list_find_custom(g_list_first(child_list),
- lang, __compare_langs);
+ extract_lang, __compare_langs);
if (found) {
- list = g_list_append(list, strdup(lang));
- child_list = g_list_remove_link(child_list, found);
- free(found->data);
- g_list_free(found);
- free(dup_lang);
+ tmp = (char *)found->data;
+ child_list = g_list_remove(child_list, tmp);
+ list = g_list_append(list, tmp);
+ free(parent_lang);
+ free(extract_lang);
return list;
}
+ free(extract_lang);
found = g_list_find_custom(g_list_first(child_list),
- token, __compare_langs);
+ parent_lang, __compare_langs);
if (found) {
- list = g_list_append(list, strdup(token));
- child_list = g_list_remove_link(child_list, found);
- free(found->data);
- g_list_free(found);
- free(dup_lang);
+ tmp = (char *)found->data;
+ child_list = g_list_remove(child_list, tmp);
+ list = g_list_append(list, tmp);
+ free(parent_lang);
return list;
}
- free(dup_lang);
+ free(parent_lang);
child_iter = g_list_first(child_list);
while (child_iter) {
return list;
}
+static GList *__append_default_langs(GList *list)
+{
+ const char *langs[] = {"en_US", "en_GB", "en"};
+ unsigned int i;
+ GList *found;
+
+ for (i = 0; i < (sizeof(langs) / sizeof(langs[0])); i++) {
+ found = g_list_find_custom(g_list_first(list), langs[i],
+ __compare_langs);
+ if (found == NULL)
+ list = g_list_append(list, strdup(langs[i]));
+ }
+
+ return list;
+}
+
static char *__get_language(const char *lang)
{
GHashTable *table;
g_list_free_full(list, free);
g_hash_table_destroy(table);
+ lang_list = __append_default_langs(lang_list);
iter = g_list_first(lang_list);
while (iter) {
language = (char *)iter->data;
}
g_list_free_full(lang_list, free);
- n = sizeof(buf) - strlen(buf) - 1;
- strncat(buf, ":", n);
- n = sizeof(buf) - strlen(buf) - 1;
- strncat(buf, "en_US:en_GB:en", n);
-
return strdup(buf);
}
setenv("LANGUAGE", language, 1);
free(language);
} else {
- setenv("LANGUAGE", language, 1);
+ setenv("LANGUAGE", lang, 1);
}
setenv("LANG", lang, 1);
setenv("LC_MESSAGES", lang, 1);
return -1;
}
+ if (dir) {
+ if (__locale_dir)
+ free(__locale_dir);
+ __locale_dir = strdup(dir);
+ }
+
__update_lang();
__update_region();
if (r == NULL)
_ERR("appcore: setlocale() error");
- if (dir) {
- if (__locale_dir)
- free(__locale_dir);
- __locale_dir = strdup(dir);
- }
-
r = bindtextdomain(domain, dir);
if (r == NULL)
_ERR("appcore: bindtextdomain() error");