EINTERN Eina_List * ech_language_enumerate(void) { Eina_List *e_lang_list, *blang_list = NULL; FILE *output; char line[32]; e_lang_list = e_intl_language_list(); /* Get list of all locales and start making map */ #ifdef __OpenBSD__ output = popen("ls /usr/share/locale", "r"); #else output = popen("locale -a", "r"); #endif if (!output) return 0; while (fscanf(output, "%[^\n]\n", line) == 1) { E_Locale_Parts *locale_parts; char *basic_language; unsigned int i = 0; locale_parts = e_intl_locale_parts_get(line); if (!locale_parts) continue; if (locale_parts->mask & E_INTL_LOC_REGION) basic_language = e_intl_locale_parts_combine(locale_parts, E_INTL_LOC_LANG | E_INTL_LOC_REGION); else basic_language = strdup(locale_parts->lang); e_intl_locale_parts_free(locale_parts); if (!basic_language) continue; while (basic_language_predefined_pairs[i].locale_key) { /* if basic language is supported by E and System*/ if (!strncmp(basic_language_predefined_pairs[i].locale_key, basic_language, strlen(basic_language))) { if ((!blang_list) || (!eina_list_data_find(blang_list, &basic_language_predefined_pairs[i]))) blang_list = eina_list_append(blang_list, &basic_language_predefined_pairs[i]); break; } i++; } free(basic_language); } pclose(output); E_FREE_LIST(e_lang_list, free); return blang_list; }
/* * TODO * - Add error dialogs explaining any errors while setting the locale * * Locale aliases need to be configured * * Locale is invalid * * Message files are not found for this locale, then we have (en_US, POSIX, C) * - Add support of compound locales i.e. (en_US;zh_CN;C) ==Defer== * - Add Configuration for to-be-set environment variables */ EAPI void e_intl_language_set(const char *lang) { int set_envars; int ok; set_envars = 1; /* NULL lang means set everything back to the original environment * defaults */ if (!lang) { e_util_env_set("LANG", _e_intl_orig_lang); if (!lang) lang = getenv("LC_ALL"); if (!lang) lang = getenv("LANG"); set_envars = 0; } E_FREE(_e_intl_language_alias); _e_intl_language_alias = _e_intl_locale_alias_get(lang); E_FREE(_e_intl_language); if (lang) _e_intl_language = strdup(lang); else _e_intl_language = NULL; ok = 1; if (strcmp(_e_intl_language_alias, "C")) { ok = _e_intl_locale_validate(_e_intl_language_alias); if (!ok) { char *p, *new_lang; new_lang = _e_intl_language_alias; p = strchr(new_lang, '.'); if (p) *p = 0; _e_intl_language_alias = strdup(new_lang); E_FREE(new_lang); ok = _e_intl_locale_validate(_e_intl_language_alias); } } if (!ok) { fprintf(stderr, "The locale '%s' cannot be found on your " "system. Please install this locale or try " "something else.", _e_intl_language_alias); return; } /* Only set env vars is a non NULL locale was passed */ if (set_envars) { e_util_env_set("LANG", lang); /* Unset LANGUAGE, apparently causes issues if set */ e_util_env_set("LANGUAGE", NULL); efreet_lang_reset(); setlocale(LC_ALL, lang); } else { setlocale(LC_ALL, ""); } if (_e_intl_language) { char *locale_path; locale_path = _e_intl_language_path_find(_e_intl_language_alias); if (!locale_path) { E_Locale_Parts *locale_parts; locale_parts = e_intl_locale_parts_get(_e_intl_language_alias); /* If locale is C or some form of en don't report an error */ if ((!locale_parts) && (strcmp(_e_intl_language_alias, "C"))) { fprintf(stderr, "An error occurred setting your locale. \n\n" "The locale you have chosen '%s' appears to \n" "be an alias, however, it can not be resloved.\n" "Please make sure you have a 'locale.alias' \n" "file in your 'messages' path which can resolve\n" "this alias.\n\n" "Enform will not be translated.\n", _e_intl_language_alias); } else if ((locale_parts) && (locale_parts->lang) && (strcmp(locale_parts->lang, "en"))) { fprintf(stderr, "An error occurred setting your locale. \n\n" "The translation files for the locale you \n" "have chosen (%s) cannot be found in your \n" "'messages' path. \n\n" "Enform will not be translated.\n", _e_intl_language_alias); } e_intl_locale_parts_free(locale_parts); } else { #ifdef HAVE_GETTEXT bindtextdomain(PACKAGE, locale_path); textdomain(PACKAGE); bind_textdomain_codeset(PACKAGE, "UTF-8"); #endif free(locale_path); } } }