GHashTable * cc_common_language_get_initial_regions (const gchar *lang) { GHashTable *ht; char *language; gchar **langs; gint i; ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /* Add some common regions */ g_hash_table_insert (ht, g_strdup ("en_US.utf8"), g_strdup (_("United States"))); g_hash_table_insert (ht, g_strdup ("de_DE.utf8"), g_strdup (_("Germany"))); g_hash_table_insert (ht, g_strdup ("fr_FR.utf8"), g_strdup (_("France"))); g_hash_table_insert (ht, g_strdup ("es_ES.utf8"), g_strdup (_("Spain"))); g_hash_table_insert (ht, g_strdup ("zh_CN.utf8"), g_strdup (_("China"))); gdm_parse_language_name (lang, &language, NULL, NULL, NULL); langs = gdm_get_all_language_names (); for (i = 0; langs[i]; i++) { gchar *l, *s; gdm_parse_language_name (langs[i], &l, NULL, NULL, NULL); if (g_strcmp0 (language, l) == 0) { if (!g_hash_table_lookup (ht, langs[i])) { s = gdm_get_region_from_name (langs[i], NULL); g_hash_table_insert (ht, g_strdup (langs[i]), s); } } g_free (l); } g_strfreev (langs); g_free (language); return ht; }
char * gdm_normalize_language_name (const char *name) { char *normalized_name; char *language_code; char *territory_code; char *codeset; char *modifier; if (name[0] == '\0') { return NULL; } gdm_parse_language_name (name, &language_code, &territory_code, &codeset, &modifier); normalized_name = construct_language_name (language_code, territory_code, codeset, modifier); g_free (language_code); g_free (territory_code); g_free (codeset); g_free (modifier); return normalized_name; }
static void gdm_language_chooser_widget_add_language (GdmLanguageChooserWidget *widget, const char *name) { char *language; char *normalized_name; char *readable_language; char *lang_tag; char *tagged; normalized_name = gdm_normalize_language_name (name); gdm_parse_language_name (name, &lang_tag, NULL, NULL, NULL); language = gdm_get_language_from_name (normalized_name, normalized_name); readable_language = gdm_get_language_from_name (normalized_name, NULL); tagged = g_strdup_printf ("<span lang=\"%s\">%s</span>", lang_tag, language); if (language != NULL) { gdm_chooser_widget_add_item (GDM_CHOOSER_WIDGET (widget), normalized_name, NULL, tagged, readable_language, 0, FALSE, FALSE, NULL, NULL); g_free (language); } g_free (readable_language); g_free (tagged); g_free (lang_tag); g_free (normalized_name); }
static gboolean language_has_font (const gchar *locale) { const FcCharSet *charset; FcPattern *pattern; FcObjectSet *object_set; FcFontSet *font_set; gchar *language_code; gboolean is_displayable; is_displayable = FALSE; pattern = NULL; object_set = NULL; font_set = NULL; if (!gdm_parse_language_name (locale, &language_code, NULL, NULL, NULL)) return FALSE; charset = FcLangGetCharSet ((FcChar8 *) language_code); if (!charset) { /* fontconfig does not know about this language */ is_displayable = TRUE; } else { /* see if any fonts support rendering it */ pattern = FcPatternBuild (NULL, FC_LANG, FcTypeString, language_code, NULL); if (pattern == NULL) goto done; object_set = FcObjectSetCreate (); if (object_set == NULL) goto done; font_set = FcFontList (NULL, pattern, object_set); if (font_set == NULL) goto done; is_displayable = (font_set->nfont > 0); } done: if (font_set != NULL) FcFontSetDestroy (font_set); if (object_set != NULL) FcObjectSetDestroy (object_set); if (pattern != NULL) FcPatternDestroy (pattern); g_free (language_code); return is_displayable; }
static gboolean add_locale (const char *language_name, gboolean utf8_only) { GdmLocale *locale; GdmLocale *old_locale; char *name; gboolean is_utf8 = FALSE; g_return_val_if_fail (language_name != NULL, FALSE); g_return_val_if_fail (*language_name != '\0', FALSE); language_name_get_codeset_details (language_name, NULL, &is_utf8); if (is_utf8) { name = g_strdup (language_name); } else if (utf8_only) { name = g_strdup_printf ("%s.utf8", language_name); language_name_get_codeset_details (name, NULL, &is_utf8); if (!is_utf8) { g_free (name); return FALSE; } } else { name = g_strdup (language_name); } if (!language_name_is_valid (name)) { g_debug ("Ignoring '%s' as a locale, since it's invalid", name); g_free (name); return FALSE; } locale = g_new0 (GdmLocale, 1); gdm_parse_language_name (name, &locale->language_code, &locale->territory_code, &locale->codeset, &locale->modifier); g_free (name); name = NULL; #ifdef WITH_INCOMPLETE_LOCALES if (utf8_only) { if (locale->territory_code == NULL || locale->modifier) { g_debug ("Ignoring '%s' as a locale, since it lacks territory code or modifier", name); gdm_locale_free (locale); return FALSE; } } #endif locale->id = construct_language_name (locale->language_code, locale->territory_code, NULL, locale->modifier); locale->name = construct_language_name (locale->language_code, locale->territory_code, locale->codeset, locale->modifier); #ifndef WITH_INCOMPLETE_LOCALES if (!gdm_language_has_translations (locale->name) && !gdm_language_has_translations (locale->id) && !gdm_language_has_translations (locale->language_code) && utf8_only) { g_debug ("Ignoring '%s' as a locale, since it lacks translations", locale->name); gdm_locale_free (locale); return FALSE; } #endif if (!utf8_only) { g_free (locale->id); locale->id = g_strdup (locale->name); } old_locale = g_hash_table_lookup (gdm_available_locales_map, locale->id); if (old_locale != NULL) { if (strlen (old_locale->name) > strlen (locale->name)) { gdm_locale_free (locale); return FALSE; } } g_hash_table_insert (gdm_available_locales_map, g_strdup (locale->id), locale); return TRUE; }
static void fcitx_im_dialog_init(FcitxImDialog* self) { gtk_window_set_title(GTK_WINDOW(self), _("Add input method")); gtk_window_set_modal(GTK_WINDOW(self), TRUE); gtk_dialog_add_buttons(GTK_DIALOG(self), _("_Cancel"), GTK_RESPONSE_CANCEL, _("_OK"), GTK_RESPONSE_OK, NULL ); g_signal_connect(self, "response", G_CALLBACK(_fcitx_im_dialog_response_cb), NULL); self->langset = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); self->builder = gtk_builder_new(); gtk_builder_add_from_resource(self->builder, "/org/fcitx/fcitx-config-gtk3/im_dialog.ui", NULL); const gchar* lang = _get_current_lang(); gchar* language = NULL, *territory = NULL; gdm_parse_language_name(lang, &language, &territory, NULL, NULL); if (!language || language[0] == '\0') { self->language = g_strdup("C"); } else { gboolean tisempty = (!territory || territory[0] == '\0'); self->language = g_strdup_printf("%s%s%s", language, tisempty ? "" : "_", tisempty ? "" : territory); } g_free(language); g_free(territory); #define _GET_OBJECT(NAME) \ self->NAME = (typeof(self->NAME)) gtk_builder_get_object(self->builder, #NAME); _GET_OBJECT(availimstore) _GET_OBJECT(availimview) _GET_OBJECT(filterentry) _GET_OBJECT(filtermodel) _GET_OBJECT(onlycurlangcheckbox) _GET_OBJECT(sortmodel) gtk_entry_set_placeholder_text(GTK_ENTRY(self->filterentry), _("Search Input Method")); gtk_widget_set_size_request(GTK_WIDGET(self), 400, 300); gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(self->filtermodel), (GtkTreeModelFilterVisibleFunc) _fcitx_im_dialog_filter_func, self , NULL); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(self->sortmodel), IM_LIST_IM, _fcitx_im_dialog_sort_func, self, NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(self->sortmodel), IM_LIST_IM, GTK_SORT_ASCENDING); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self->availimview), FALSE); GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self->availimview)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(_fcitx_im_dialog_im_selection_changed), self); g_signal_connect(G_OBJECT(self->filterentry), "changed", G_CALLBACK(_fcitx_im_dialog_filtertext_changed), self); g_signal_connect(G_OBJECT(self->onlycurlangcheckbox), "toggled", G_CALLBACK(_fcitx_im_dialog_onlycurlangcheckbox_toggled), self); g_signal_connect(G_OBJECT(self->filterentry), "icon-press", G_CALLBACK (icon_press_cb), NULL); }