Example #1
0
const char *
get_language_name (PangoLanguage *language)
{
  languages_init ();

  return (const char *) g_hash_table_lookup (language_map, language);
}
Example #2
0
/**
 * gnome_get_language_from_code:
 * @code: an ISO 639 code string
 * @translation: (allow-none): a locale string
 *
 * Gets the language name for @code. If @translation is provided the
 * returned string is translated accordingly.
 *
 * Return value: (transfer full): the language name. Caller takes
 * ownership.
 *
 * Since: 3.8
 */
char *
gnome_get_language_from_code (const char *code,
                              const char *translation)
{
        g_return_val_if_fail (code != NULL, NULL);

        languages_init ();

        return get_translated_language (code, translation);
}
Example #3
0
/**
 * gnome_get_country_from_locale:
 * @locale: a locale string
 * @translation: (allow-none): a locale string
 *
 * Gets the country description for @locale. If @translation is
 * provided the returned string is translated accordingly.
 *
 * Return value: (transfer full): the country description. Caller
 * takes ownership.
 *
 * Since: 3.8
 */
char *
gnome_get_country_from_locale (const char *locale,
                               const char *translation)
{
        GString *full_name;
        g_autofree char *language_code = NULL;
        g_autofree char *territory_code = NULL;
        g_autofree char *codeset_code = NULL;
        g_autofree char *langinfo_codeset = NULL;
        g_autofree char *translated_language = NULL;
        g_autofree char *translated_territory = NULL;
        gboolean is_utf8 = TRUE;

        g_return_val_if_fail (locale != NULL, NULL);
        g_return_val_if_fail (*locale != '\0', NULL);

        full_name = g_string_new (NULL);

        languages_init ();
        territories_init ();

        gnome_parse_locale (locale,
                            &language_code,
                            &territory_code,
                            &codeset_code,
                            NULL);

        if (territory_code == NULL) {
                goto out;
        }

        translated_territory = get_translated_territory (territory_code, translation);
        g_string_append (full_name, translated_territory);

	if (is_unique_territory (territory_code)) {
		goto out;
	}

        if (language_code != NULL) {
                translated_language = get_translated_language (language_code, translation);
        }
        if (translated_language != NULL) {
                g_string_append_printf (full_name,
                                        " (%s)",
                                        translated_language);
        }

        language_name_get_codeset_details (translation, &langinfo_codeset, &is_utf8);

        if (codeset_code == NULL && langinfo_codeset != NULL) {
                codeset_code = g_strdup (langinfo_codeset);
        }

        if (!is_utf8 && codeset_code) {
                g_string_append_printf (full_name,
                                        " [%s]",
                                        codeset_code);
        }

 out:
        if (full_name->len == 0) {
                g_string_free (full_name, TRUE);
                return NULL;
        }

        return g_string_free (full_name, FALSE);
}