[gtk/wip/chergert/spellcheck: 8/9] spellcheck: replace language code with loaded language




commit 4ad01e2d218f771ae7c3a47d34f82ed609cd42a5
Author: Christian Hergert <chergert redhat com>
Date:   Mon Mar 15 15:29:34 2021 -0700

    spellcheck: replace language code with loaded language
    
    If enchant returns us a dictionary that is slightly different than the one
    we requested, then replace the language code with what was loaded. This
    can be used to deduplicate later.

 gtk/gtkspellcheck.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/gtk/gtkspellcheck.c b/gtk/gtkspellcheck.c
index eae0275f15..bfed875074 100644
--- a/gtk/gtkspellcheck.c
+++ b/gtk/gtkspellcheck.c
@@ -469,6 +469,26 @@ gtk_enchant_list_corrections (GtkSpellLanguage *language,
   return G_LIST_MODEL (model);
 }
 
+static void
+gtk_enchant_init_language_cb (const char * const  code,
+                              const char * const  provider_name,
+                              const char * const  provider_desc,
+                              const char * const  provider_file,
+                              void               *user_data)
+{
+  GtkSpellLanguage *language = user_data;
+
+  g_assert (language != NULL);
+  g_assert (code != NULL);
+
+  /* Replace the language code so we can deduplicate based on what
+   * dictionary was actually loaded. Otherwise we could end up with
+   * en_US and en_US.UTF-8 as two separate dictionaries.
+   */
+  g_free (language->code);
+  language->code = g_strdup (code);
+}
+
 static gboolean
 gtk_enchant_init_language (GtkSpellLanguage *language)
 {
@@ -477,6 +497,10 @@ gtk_enchant_init_language (GtkSpellLanguage *language)
   if (!(language->native = enchant_broker_request_dict (broker, language->code)))
     return FALSE;
 
+  enchant_dict_describe (language->native,
+                         gtk_enchant_init_language_cb,
+                         language);
+
   return TRUE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]