- Clean up the best match function and make it work

- In e_path the user list should be before the default list
- Add a function to list all available locales wrapping "locale -a"


SVN revision: 18647
This commit is contained in:
stffrdhrn 2005-11-26 11:44:02 +00:00 committed by stffrdhrn
parent 2551e897ed
commit 26b69ad8bd
2 changed files with 65 additions and 39 deletions

View File

@ -33,6 +33,7 @@ static Evas_Hash *_e_intl_language_path_scan(E_Path *path);
static void _e_intl_language_hash_free(Evas_Hash *language_hash); static void _e_intl_language_hash_free(Evas_Hash *language_hash);
static char *_e_intl_language_hash_find(Evas_Hash *language_hash, char *language); static char *_e_intl_language_hash_find(Evas_Hash *language_hash, char *language);
static int _e_intl_language_list_find(Evas_List *language_list, char *language); static int _e_intl_language_list_find(Evas_List *language_list, char *language);
static Evas_List *_e_intl_language_system_locales_get(void);
Evas_Bool _e_intl_cb_free_language_hash(Evas_Hash *hash, const char *key, void *data, void *fdata); Evas_Bool _e_intl_cb_free_language_hash(Evas_Hash *hash, const char *key, void *data, void *fdata);
static Evas_List *_e_intl_language_dir_scan(const char *dir); static Evas_List *_e_intl_language_dir_scan(const char *dir);
static int _e_intl_cb_exit(void *data, int type, void *event); static int _e_intl_cb_exit(void *data, int type, void *event);
@ -483,53 +484,57 @@ _e_intl_cb_free_language_hash(Evas_Hash *hash __UNUSED__, const char *key __UNUS
static char * static char *
_e_intl_language_hash_find(Evas_Hash *language_hash, char *language) _e_intl_language_hash_find(Evas_Hash *language_hash, char *language)
{ {
Evas_List *l; Evas_List *l;
Evas_List *all_languages; Evas_List *all_languages;
char *best_language; char *best_language;
char *directory; int best_chars;
int state; char *directory;
if (!language_hash) return NULL; if (!language_hash) return NULL;
if (!language) return NULL; if (!language) return NULL;
best_language = NULL; best_language = NULL;
best_chars = 0;
all_languages = e_intl_language_list(); all_languages = e_intl_language_list();
/* Do a best match: /* Do a best match:
* If language is ja_JP.UTF-8 we should match ja * If language is ja_JP.UTF-8 we should match ja
* If language is zh we should match the first in the list, of zh_CN and zh_TW * If language is zh we should match the first in the list of zh_CN and zh_TW
*/ */
for ( l = all_languages ; l ; l = l->next ) for ( l = all_languages ; l ; l = l->next )
{ {
char *lang; char *list_lang;
int comp_len; int cmp_ret;
int lang_len;
int language_len;
lang = l->data; list_lang = l->data;
lang_len = strlen(lang); cmp_ret = strncmp(list_lang, language, 2);
language_len = strlen(language); if ( cmp_ret == 0 )
/* return shorter */
comp_len = lang_len > language_len ? language_len : lang_len;
if ( !strncmp(lang, language, comp_len) )
{ {
if ( best_language == NULL ) int list_lang_len;
{ int language_len;
best_language = lang; int compare_len;
if ( lang_len > language_len )
state = 1; /* looking for shorter */
else
state = 0; /* looking for longer */
}
else if ( (state == 1 && lang_len > language_len) ||
(state == 0 && lang_len < language_len) )
best_language = lang;
if ( strlen(best_language) == language_len ) break; if (best_language == NULL)
{
best_language = list_lang;
best_chars = 2;
continue;
}
list_lang_len = strlen(list_lang);
language_len = strlen(language);
compare_len = list_lang_len < language_len ? list_lang_len :
language_len;
if ( (compare_len > best_chars ) &&
!strncmp(list_lang, language, compare_len)
)
{
best_language = list_lang;
best_chars = compare_len;
}
} }
} }
directory = evas_hash_find(language_hash, best_language); directory = evas_hash_find(language_hash, best_language);
while (all_languages) while (all_languages)
@ -619,6 +624,27 @@ _e_intl_language_dir_scan(const char *dir)
return languages; return languages;
} }
static Evas_List *
_e_intl_language_system_locales_get(void)
{
Evas_List *locales;
FILE *output;
locales = NULL;
output = popen("locale -a", "r");
if ( output )
{
char line[32];
while ( fscanf(output, "%[^\n]\n", line) == 1)
{
locales = evas_list_append(locales, strdup(line));
}
pclose(output);
}
return locales;
}
static Evas_List * static Evas_List *
_e_intl_imc_path_scan(E_Path *path) _e_intl_imc_path_scan(E_Path *path)
{ {

View File

@ -334,7 +334,7 @@ e_path_evas_append(E_Path *ep, Evas *evas)
if (dir_list) evas_list_free(dir_list); if (dir_list) evas_list_free(dir_list);
} }
/* compine default_list and and user_list int and easy to use list */ /* combine default_list and and user_list in and easy to use list */
Evas_List * Evas_List *
e_path_dir_list_get(E_Path *ep) e_path_dir_list_get(E_Path *ep)
{ {
@ -345,14 +345,6 @@ e_path_dir_list_get(E_Path *ep)
dir_list = NULL; dir_list = NULL;
for (l = ep->default_dir_list; l; l = l->next)
{
epd = l->data;
new_epd = malloc(sizeof(E_Path_Dir));
new_epd->dir = strdup(epd->dir);
dir_list = evas_list_append(dir_list, new_epd);
}
if (ep->user_dir_list) if (ep->user_dir_list)
{ {
for (l = *(ep->user_dir_list); l; l = l->next) for (l = *(ep->user_dir_list); l; l = l->next)
@ -364,6 +356,14 @@ e_path_dir_list_get(E_Path *ep)
} }
} }
for (l = ep->default_dir_list; l; l = l->next)
{
epd = l->data;
new_epd = malloc(sizeof(E_Path_Dir));
new_epd->dir = strdup(epd->dir);
dir_list = evas_list_append(dir_list, new_epd);
}
return dir_list; return dir_list;
} }