2005-04-11 13:25:52 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
#include "e.h"
|
|
|
|
|
|
|
|
/* TODO List:
|
2005-04-12 01:46:43 -07:00
|
|
|
*
|
|
|
|
* * load/save language in config so u can change language runtime via a gui and/or ipc
|
|
|
|
* * add ipc to get/set/list languages, get language name, simplified language string, etc. (so a config tool can be written to display supported languages and be able to select from them)
|
|
|
|
* * add more language names to the language name list list in e_intl_language_name_get()
|
|
|
|
* * as we get translations add languages to the simplified lang list (C and en are currently the same, ja is a test translation - incomplete)
|
2005-04-11 13:25:52 -07:00
|
|
|
*/
|
|
|
|
|
2005-04-11 16:32:24 -07:00
|
|
|
static char *_e_intl_language = NULL;
|
|
|
|
static Evas_List *_e_intl_languages = NULL;
|
|
|
|
|
|
|
|
#define ADD_LANG(lang) _e_intl_languages = evas_list_append(_e_intl_languages, lang)
|
|
|
|
|
2005-04-11 13:25:52 -07:00
|
|
|
int
|
|
|
|
e_intl_init(void)
|
|
|
|
{
|
2005-04-11 19:47:21 -07:00
|
|
|
if (_e_intl_languages) return 1;
|
2005-04-11 16:32:24 -07:00
|
|
|
|
2005-04-13 19:50:52 -07:00
|
|
|
/* supporeted languages - as we get translations - add them here
|
|
|
|
*
|
|
|
|
* if you add a language:
|
|
|
|
*
|
|
|
|
* NOTE: add a language NAME for this in e_intl_language_name_get() if
|
|
|
|
* there isn't one yet (use the english name - then we will add
|
|
|
|
* translations of the language names to the .po file)
|
|
|
|
* NOTE: add a translation logic list to take all possible ways to address
|
|
|
|
* a language locale and convert it to a simplified one that is in
|
|
|
|
* the list here below. languages can often have multiple ways of
|
|
|
|
* being addressed (same language spoken in multiple countries or
|
|
|
|
* many variants of the language). this translation allows all the
|
|
|
|
* variants to be used and mapped to a simple "single" name for that
|
|
|
|
* language. if the differences in variants are large (eg simplified
|
|
|
|
* vs. traditional chinese) we may refer to them as separate languages
|
|
|
|
* entirely.
|
|
|
|
*/
|
2005-05-03 01:06:50 -07:00
|
|
|
ADD_LANG("");
|
|
|
|
ADD_LANG("en_US.UTF-8");
|
|
|
|
ADD_LANG("ja_JP.UTF-8");
|
|
|
|
ADD_LANG("fr_FR.UTF-8");
|
|
|
|
ADD_LANG("es_AR.UTF-8");
|
|
|
|
ADD_LANG("pt_BR.UTF-8");
|
|
|
|
ADD_LANG("fi_FI.UTF-8");
|
|
|
|
ADD_LANG("ru_RU.UTF-8");
|
|
|
|
ADD_LANG("bg_BG.UTF-8");
|
|
|
|
ADD_LANG("de_DE.UTF-8");
|
|
|
|
ADD_LANG("pl_PL.UTF-8");
|
|
|
|
ADD_LANG("zh_CN.UTF-8");
|
|
|
|
ADD_LANG("hu_HU.UTF-8");
|
|
|
|
ADD_LANG("sl_SI.UTF-8");
|
|
|
|
ADD_LANG("it_IT.UTF-8");
|
2005-04-11 16:32:24 -07:00
|
|
|
|
2005-04-11 19:47:21 -07:00
|
|
|
/* FIXME: NULL == use LANG. make this read a config value if it exists */
|
2005-04-13 22:49:17 -07:00
|
|
|
e_intl_language_set(getenv("LANG"));
|
2005-04-11 19:47:21 -07:00
|
|
|
return 1;
|
2005-04-11 16:32:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
e_intl_shutdown(void)
|
|
|
|
{
|
2005-04-12 01:46:43 -07:00
|
|
|
free(_e_intl_language);
|
|
|
|
_e_intl_language = NULL;
|
2005-04-13 12:47:25 -07:00
|
|
|
evas_list_free(_e_intl_languages);
|
2005-04-11 19:47:21 -07:00
|
|
|
return 1;
|
2005-04-11 16:32:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
e_intl_language_set(const char *lang)
|
|
|
|
{
|
2005-04-11 19:47:21 -07:00
|
|
|
if (_e_intl_language) free(_e_intl_language);
|
|
|
|
if (!lang) lang = getenv("LANG");
|
2005-04-18 00:15:48 -07:00
|
|
|
if (lang)
|
|
|
|
{
|
|
|
|
_e_intl_language = strdup(lang);
|
|
|
|
e_util_env_set("LANG", _e_intl_language);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_intl_language = NULL;
|
|
|
|
}
|
2005-05-03 01:06:50 -07:00
|
|
|
if (setlocale(LC_ALL, "") == NULL)
|
|
|
|
{
|
|
|
|
perror("setlocale() :");
|
|
|
|
if (_e_intl_language)
|
|
|
|
printf("An error occured when trying to use the locale: %s\nDetails:\n",
|
|
|
|
_e_intl_language);
|
|
|
|
else
|
|
|
|
printf("An error occured trying to use the default locale\n");
|
|
|
|
}
|
2005-04-11 19:47:21 -07:00
|
|
|
bindtextdomain(PACKAGE, LOCALE_DIR);
|
|
|
|
textdomain(PACKAGE);
|
2005-04-12 01:46:43 -07:00
|
|
|
// XSetLocaleModifiers("");
|
2005-04-11 19:47:21 -07:00
|
|
|
bind_textdomain_codeset(PACKAGE, "UTF-8");
|
2005-04-11 16:32:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
e_intl_language_get(void)
|
|
|
|
{
|
2005-04-11 19:47:21 -07:00
|
|
|
return _e_intl_language;
|
2005-04-11 16:32:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define IFL(l) if (!strcmp(lang, l)) return
|
|
|
|
const char *
|
|
|
|
e_intl_language_name_get(const char *lang)
|
|
|
|
{
|
2005-04-11 19:47:21 -07:00
|
|
|
if (!lang) return "None";
|
2005-04-13 19:50:52 -07:00
|
|
|
/* this is a list of DISTINCT languages. some languages have variants that
|
|
|
|
* are different enough to justify being listed separately as distinct
|
|
|
|
* languages here. this is intended for use in a gui that lets you select
|
|
|
|
* a language, with e being able to give a name for the given language
|
|
|
|
* encoding (once simplfied)
|
|
|
|
*/
|
2005-04-11 19:47:21 -07:00
|
|
|
/* FIXME: add as many as we can to this */
|
|
|
|
IFL("") "None";
|
|
|
|
IFL("C") "None";
|
|
|
|
IFL("bg") "Bulgarian";
|
|
|
|
IFL("bs") "Bosnian";
|
|
|
|
IFL("ca") "Catalan";
|
|
|
|
IFL("cs") "Czech";
|
|
|
|
IFL("cy") "Welsh";
|
|
|
|
IFL("da") "Danish";
|
|
|
|
IFL("de") "German";
|
|
|
|
IFL("el") "Greek";
|
|
|
|
IFL("en") "English";
|
2005-04-14 23:29:43 -07:00
|
|
|
IFL("es") "Spanish";
|
2005-04-11 19:47:21 -07:00
|
|
|
IFL("eu") "Basque";
|
|
|
|
IFL("fa") "Persian";
|
|
|
|
IFL("fr") "French";
|
|
|
|
IFL("fi") "Finnish";
|
|
|
|
IFL("gl") "Galician";
|
|
|
|
IFL("hi") "Hindi";
|
|
|
|
IFL("hr") "Croatian";
|
|
|
|
IFL("hu") "Hungarian";
|
|
|
|
IFL("id") "Indonesian";
|
|
|
|
IFL("it") "Italian";
|
2005-04-13 19:50:52 -07:00
|
|
|
IFL("ja") "Japanese";
|
2005-04-11 19:47:21 -07:00
|
|
|
IFL("kr") "Korean";
|
|
|
|
IFL("lt") "Lithuanian";
|
|
|
|
IFL("lv") "Latvian";
|
|
|
|
IFL("nl") "Dutch";
|
2005-04-13 12:49:35 -07:00
|
|
|
IFL("no") "Norwegian";
|
|
|
|
IFL("nb") "Norwegian Bokmal";
|
|
|
|
IFL("nn") "Norwegian Nynorsk";
|
2005-04-11 19:47:21 -07:00
|
|
|
IFL("pl") "Polish";
|
|
|
|
IFL("pt") "Portuguese";
|
|
|
|
IFL("ro") "Romanian";
|
|
|
|
IFL("ru") "Russian";
|
|
|
|
IFL("sk") "Slovak";
|
|
|
|
IFL("sl") "Slovenian";
|
|
|
|
IFL("sq") "Albanian";
|
|
|
|
IFL("sr") "Serbian";
|
|
|
|
IFL("sv") "Swedish";
|
|
|
|
IFL("tr") "Tuirkish";
|
|
|
|
IFL("uk") "Ukrainian";
|
|
|
|
IFL("vi") "Vietnamese";
|
2005-04-14 23:29:43 -07:00
|
|
|
/* must keep both - politically sensitive */
|
2005-04-26 08:06:06 -07:00
|
|
|
IFL("zh_CN") "Chinese (Simplified)";
|
2005-04-11 19:47:21 -07:00
|
|
|
IFL("zh_TW") "Chinese (Traditional)";
|
|
|
|
return "Unknown";
|
2005-04-11 16:32:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ISL(l) (!strcasecmp(buf, l))
|
|
|
|
const char *
|
|
|
|
e_intl_language_simple_get(const char *lang)
|
|
|
|
{
|
2005-04-13 19:50:52 -07:00
|
|
|
static char buf[128];
|
|
|
|
char *p;
|
2005-04-11 19:41:14 -07:00
|
|
|
|
2005-04-11 19:47:21 -07:00
|
|
|
if (!lang) return "C";
|
2005-04-13 19:50:52 -07:00
|
|
|
/* strip off the charset stuff after any "." eg: "en_US.UTF-8" -> "en_US" */
|
2005-04-11 19:47:21 -07:00
|
|
|
strncpy(buf, lang, sizeof(buf) - 1);
|
|
|
|
p = strchr(buf, '.');
|
|
|
|
if (p) *p = 0;
|
2005-04-12 01:46:43 -07:00
|
|
|
/* do we want to split this inot the different forms of english?
|
|
|
|
* ie american vs british? or australian? etc.
|
|
|
|
*/
|
2005-04-13 19:50:52 -07:00
|
|
|
/* for known specific mappings - do them first here */
|
|
|
|
if (ISL("en") || ISL("en_US") || ISL("en_GB") || ISL("en_GB@euro") ||
|
|
|
|
ISL("en_CA") || ISL("en_AU") || ISL("en_NZ") || ISL("en_RN"))
|
2005-04-11 19:47:21 -07:00
|
|
|
return "en";
|
2005-04-11 23:34:17 -07:00
|
|
|
if (ISL("ja") || ISL("ja_JP") || ISL("JP"))
|
2005-04-11 19:47:21 -07:00
|
|
|
return "ja";
|
2005-04-13 19:50:52 -07:00
|
|
|
if (ISL("fr") || ISL("fr_FR") || ISL("FR") || ISL("fr_FR@euro"))
|
|
|
|
return "fr";
|
2005-04-14 23:29:43 -07:00
|
|
|
if (ISL("es") || ISL("es_ES") || ISL("ES") || ISL("es_ES@euro") ||
|
2005-04-18 00:15:48 -07:00
|
|
|
ISL("es_AR") || ISL("AR"))
|
2005-04-14 23:29:43 -07:00
|
|
|
return "es";
|
2005-04-18 00:15:48 -07:00
|
|
|
if (ISL("pt") || ISL("pt_PT") || ISL("PT") || ISL("pt_PT@euro") ||
|
|
|
|
ISL("pt_BR") || ISL("BR"))
|
|
|
|
return "pt";
|
|
|
|
if (ISL("fi") || ISL("fi_FI") || ISL("FI") || ISL("fi_FI@euro"))
|
|
|
|
return "fi";
|
2005-04-18 20:19:18 -07:00
|
|
|
if (ISL("ru") || ISL("ru_RU") || ISL("RU"))
|
|
|
|
return "ru";
|
2005-04-19 06:42:08 -07:00
|
|
|
if (ISL("bg") || ISL("bg_BG") || ISL("BG"))
|
|
|
|
return "bg";
|
2005-04-19 20:14:07 -07:00
|
|
|
if (ISL("de") || ISL("de_DE") || ISL("DE") || ISL("de_DE@euro") ||
|
|
|
|
ISL("de_AT") || ISL("AT") || ISL("de_AT@euro"))
|
|
|
|
return "de";
|
2005-04-21 20:06:27 -07:00
|
|
|
if (ISL("pl") || ISL("pl_PL") || ISL("PL") || ISL("pl_PL@euro"))
|
|
|
|
return "pl";
|
2005-04-26 08:06:06 -07:00
|
|
|
if (ISL("zh") || ISL("zh_CN") || ISL("CN"))
|
|
|
|
return "zh_CN";
|
|
|
|
if (ISL("zh") || ISL("zh_TW") || ISL("TW"))
|
|
|
|
return "zh_TW";
|
|
|
|
if (ISL("hu") || ISL("hu_HU") || ISL("HU"))
|
|
|
|
return "hu";
|
2005-05-03 01:14:45 -07:00
|
|
|
if (ISL("sl") || ISL("sl_SI") || ISL("SI"))
|
2005-04-30 01:07:14 -07:00
|
|
|
return "sl";
|
2005-05-01 23:48:38 -07:00
|
|
|
if (ISL("it") || ISL("it_IT") || ISL("IT"))
|
|
|
|
return "it";
|
2005-04-13 19:50:52 -07:00
|
|
|
/* this is the default fallback - we have no special cases for this lang
|
|
|
|
* so just strip off anything after and including the _ for country region
|
|
|
|
* and just return the language encoding
|
|
|
|
*/
|
|
|
|
/* strip off anything after a "_" eg: "en_US" -> "en" */
|
|
|
|
p = strchr(buf, '_');
|
|
|
|
if (p) *p = 0;
|
|
|
|
/* we can safely retunr buf because its a static - BUT its contents will
|
|
|
|
* change if we call e_intl_language_simple_get() again - so its only
|
|
|
|
* intended for immediate use and de-reference, not for storage
|
|
|
|
*/
|
|
|
|
return buf;
|
2005-04-11 13:25:52 -07:00
|
|
|
}
|
|
|
|
|
2005-04-11 16:32:24 -07:00
|
|
|
const Evas_List *
|
|
|
|
e_intl_language_list(void)
|
2005-04-11 13:25:52 -07:00
|
|
|
{
|
2005-04-11 19:47:21 -07:00
|
|
|
return _e_intl_languages;
|
2005-04-11 13:25:52 -07:00
|
|
|
}
|