Example #1
0
EAPI void
efreet_ini_localestring_set(Efreet_Ini *ini, const char *key, const char *value)
{
    const char *lang, *country, *modifier;
    char *buf;
    int maxlen = 5; /* _, @, [, ] and \0 */

    EINA_SAFETY_ON_NULL_RETURN(ini);
    EINA_SAFETY_ON_NULL_RETURN(ini->section);
    EINA_SAFETY_ON_NULL_RETURN(key);

    lang = efreet_lang_get();
    country = efreet_lang_country_get();
    modifier = efreet_lang_modifier_get();

    maxlen += strlen(key);
    if (lang) maxlen += strlen(lang);
    if (country) maxlen += strlen(country);
    if (modifier) maxlen += strlen(modifier);

    buf = alloca(maxlen);

    if (lang && modifier && country)
        snprintf(buf, maxlen, "%s[%s_%s@%s]", key, lang, country, modifier);
    else if (lang && country)
        snprintf(buf, maxlen, "%s[%s_%s]", key, lang, country);
    else if (lang && modifier)
        snprintf(buf, maxlen, "%s[%s@%s]", key, lang, modifier);
    else if (lang)
        snprintf(buf, maxlen, "%s[%s]", key, lang);
    else
        return;

    efreet_ini_string_set(ini, buf, value);
}
Example #2
0
/*
 * Needs EAPI because of helper binaries
 */
EAPI const char *
efreet_desktop_util_cache_file(void)
{
    char tmp[PATH_MAX] = { '\0' };
    const char *cache_dir, *lang, *country, *modifier;

    if (cache_file) return cache_file;

    cache_dir = efreet_cache_home_get();
    lang = efreet_lang_get();
    country = efreet_lang_country_get();
    modifier = efreet_lang_modifier_get();

    if (lang && country && modifier)
        snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s_%s@%s.eet", cache_dir, efreet_hostname_get(), lang, country, modifier);
    else if (lang && country)
        snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s_%s.eet", cache_dir, efreet_hostname_get(), lang, country);
    else if (lang)
        snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s.eet", cache_dir, efreet_hostname_get(), lang);
    else
        snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s.eet", cache_dir, efreet_hostname_get());

    cache_file = eina_stringshare_add(tmp);
    return cache_file;
}
Example #3
0
EAPI const char *
efreet_ini_localestring_get(Efreet_Ini *ini, const char *key)
{
    const char *lang, *country, *modifier;
    const char *val = NULL;
    char *buf;
    int maxlen = 5; /* _, @, [, ] and \0 */
    int found = 0;

    EINA_SAFETY_ON_NULL_RETURN_VAL(ini, NULL);
    EINA_SAFETY_ON_NULL_RETURN_VAL(ini->section, NULL);
    EINA_SAFETY_ON_NULL_RETURN_VAL(key, NULL);

    lang = efreet_lang_get();
    country = efreet_lang_country_get();
    modifier = efreet_lang_modifier_get();

    maxlen += strlen(key);
    if (lang) maxlen += strlen(lang);
    if (country) maxlen += strlen(country);
    if (modifier) maxlen += strlen(modifier);

    buf = alloca(maxlen);

    if (lang && modifier && country)
    {
        snprintf(buf, maxlen, "%s[%s_%s@%s]", key, lang, country, modifier);
        val = efreet_ini_string_get(ini, buf);
        if (val && (*val != '\0')) found = 1;
    }

    if (!found && lang && country)
    {
        snprintf(buf, maxlen, "%s[%s_%s]", key, lang, country);
        val = efreet_ini_string_get(ini, buf);
        if (val && (*val != '\0')) found = 1;
    }

    if (!found && lang && modifier)
    {
        snprintf(buf, maxlen, "%s[%s@%s]", key, lang, modifier);
        val = efreet_ini_string_get(ini, buf);
        if (val && (*val != '\0')) found = 1;
    }

    if (!found && lang)
    {
        snprintf(buf, maxlen, "%s[%s]", key, lang);
        val = efreet_ini_string_get(ini, buf);
        if (val && (*val != '\0')) found = 1;
    }

    if (!found)
        val = efreet_ini_string_get(ini, key);

    return val;
}
Example #4
0
int
ef_cb_locale(void)
{
   int ret = 1, i;
   struct
     {
        char *lc_message;
        char *lang;
        char *country;
        char *modifier;
     } langs[] = {
          /* these are ordered such that when we move from LANG to LC_MESSAGES
           * the LANG env will still be effect. Same with moving from
           * LC_MESSAGES to LANG */
            {"LANG=", NULL, NULL, NULL},
            {"LANG=en", "en", NULL, NULL},
            {"LANG=en@Latn", "en", NULL, "Latn"},
            {"LANG=en_US", "en", "US", NULL},
            {"LANG=en_US@Latn", "en", "US", "Latn"},
            {"LANG=en_US.blah@Latn", "en", "US", "Latn"},
            {"LC_MESSAGES=", "en", "US", "Latn"}, /* This will fallback to LANG */
            {"LC_MESSAGES=fr", "fr", NULL, NULL},
            {"LC_MESSAGES=fr@Blah", "fr", NULL, "Blah"},
            {"LC_MESSAGES=fr_FR", "fr", "FR", NULL},
            {"LC_MESSAGES=fr_FR@Blah", "fr", "FR", "Blah"},
            {"LC_MESSAGES=fr_FR.Foo@Blah", "fr", "FR", "Blah"},
            {"LC_ALL=", "fr", "FR", "Blah"}, /* this will fallback to LC_MESSAGES */
            {"LC_ALL=sr", "sr", NULL, NULL},
            {"LC_ALL=sr@Ret", "sr", NULL, "Ret"},
            {"LC_ALL=sr_YU", "sr", "YU", NULL},
            {"LC_ALL=sr_YU@Ret", "sr", "YU", "Ret"},
            {"LC_ALL=sr_YU.ssh@Ret", "sr", "YU", "Ret"},
            {NULL, NULL, NULL, NULL}
     };

   /* reset everything to blank */
   putenv("LC_ALL=");
   putenv("LC_MESSAGES=");
   putenv("LANG=");

   for (i = 0; langs[i].lc_message; i++)
     {
        const char *tmp;

        putenv(langs[i].lc_message);

        tmp = efreet_lang_get();
        if ((langs[i].lang && (!tmp || strcmp(tmp, langs[i].lang)))
            || (!langs[i].lang && tmp))
          {
             printf("efreet_lang_get() is wrong (%s) with %s\n",
                    tmp, langs[i].lang);
             ret = 0;
          }

        tmp = efreet_lang_country_get();
        if ((langs[i].country && (!tmp || strcmp(tmp, langs[i].country)))
            || (!langs[i].country && tmp))
          {
             printf("efreet_lang_country_get() is wrong (%s) with %s\n",
                    tmp, langs[i].lang);
             ret = 0;
          }

        tmp = efreet_lang_modifier_get();
        if ((langs[i].modifier && (!tmp || strcmp(tmp, langs[i].modifier)))
            || (!langs[i].modifier && tmp))
          {
             printf("efreet_lang_modifier_get() is wrong with %s with %s\n",
                    tmp, langs[i].lang);
             ret = 0;
          }

        efreet_shutdown();
        efreet_init();
     }

   return ret;
}