[gtranslator/language-list] List of languages in a config file instead iso-codes



commit 1a9ad70c721f339c858af9a80b2af16ff510ea49
Author: Daniel García Moreno <danigm wadobo com>
Date:   Sun Dec 9 13:54:03 2018 +0100

    List of languages in a config file instead iso-codes
    
    The iso codes has the list of languages codes and the list of country
    codes, but there's no a list of these two mixed.
    
    To have a custom list with language codes with region we can provide a
    custom list, like we provide the plural forms.
    
    In the future this will help us to translate language names too. Right
    now we've a list of languages in plain english.
    
    See #43

 data/gtr-languages.ini | 185 +++++++++++++++++++++++++++++++++++++++++++++++++
 data/meson.build       |   1 +
 meson.build            |   6 +-
 src/gtr-language.c     | 151 ++++++++--------------------------------
 4 files changed, 216 insertions(+), 127 deletions(-)
---
diff --git a/data/gtr-languages.ini b/data/gtr-languages.ini
new file mode 100644
index 00000000..6180b7b1
--- /dev/null
+++ b/data/gtr-languages.ini
@@ -0,0 +1,185 @@
+[Languages]
+aa=Afar
+ab=Abkhazian
+af=Afrikaans
+ak=Akan
+am=Amharic
+ar=Arabic
+an=Aragonese
+as=Assamese
+av=Avaric
+ae=Avestan
+ay=Aymara
+az=Azerbaijani
+ba=Bashkir
+bm=Bambara
+be=Belarusian
+bn=Bengali
+bh=Bihari languages
+bi=Bislama
+bo=Tibetan
+bs=Bosnian
+br=Breton
+bg=Bulgarian
+ca=Catalan; Valencian
+cs=Czech
+ch=Chamorro
+ce=Chechen
+cu=Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic
+cv=Chuvash
+kw=Cornish
+co=Corsican
+cr=Cree
+cy=Welsh
+da=Danish
+de=German
+dv=Divehi; Dhivehi; Maldivian
+dz=Dzongkha
+el=Greek, Modern (1453-)
+en=English
+eo=Esperanto
+et=Estonian
+eu=Basque
+ee=Ewe
+fo=Faroese
+fa=Persian
+fj=Fijian
+fi=Finnish
+fr=French
+fy=Western Frisian
+ff=Fulah
+gd=Gaelic; Scottish Gaelic
+ga=Irish
+gl=Galician
+gv=Manx
+gn=Guarani
+gu=Gujarati
+ht=Haitian; Haitian Creole
+ha=Hausa
+he=Hebrew
+hz=Herero
+hi=Hindi
+ho=Hiri Motu
+hr=Croatian
+hu=Hungarian
+hy=Armenian
+ig=Igbo
+io=Ido
+ii=Sichuan Yi; Nuosu
+iu=Inuktitut
+ie=Interlingue; Occidental
+ia=Interlingua (International Auxiliary Language Association)
+id=Indonesian
+ik=Inupiaq
+is=Icelandic
+it=Italian
+jv=Javanese
+ja=Japanese
+kl=Kalaallisut; Greenlandic
+kn=Kannada
+ks=Kashmiri
+ka=Georgian
+kr=Kanuri
+kk=Kazakh
+km=Central Khmer
+ki=Kikuyu; Gikuyu
+rw=Kinyarwanda
+ky=Kirghiz; Kyrgyz
+kv=Komi
+kg=Kongo
+ko=Korean
+kj=Kuanyama; Kwanyama
+ku=Kurdish
+lo=Lao
+la=Latin
+lv=Latvian
+li=Limburgan; Limburger; Limburgish
+ln=Lingala
+lt=Lithuanian
+lb=Luxembourgish; Letzeburgesch
+lu=Luba-Katanga
+lg=Ganda
+mh=Marshallese
+ml=Malayalam
+mr=Marathi
+mk=Macedonian
+mg=Malagasy
+mt=Maltese
+mn=Mongolian
+mi=Maori
+ms=Malay
+my=Burmese
+na=Nauru
+nv=Navajo; Navaho
+nr=Ndebele, South; South Ndebele
+nd=Ndebele, North; North Ndebele
+ng=Ndonga
+ne=Nepali
+nl=Dutch; Flemish
+nn=Norwegian Nynorsk; Nynorsk, Norwegian
+nb=Bokmål, Norwegian; Norwegian Bokmål
+no=Norwegian
+ny=Chichewa; Chewa; Nyanja
+oc=Occitan (post 1500); Provençal
+oj=Ojibwa
+or=Oriya
+om=Oromo
+os=Ossetian; Ossetic
+pa=Panjabi; Punjabi
+pi=Pali
+pl=Polish
+pt=Portuguese
+ps=Pushto; Pashto
+qu=Quechua
+rm=Romansh
+ro=Romanian; Moldavian; Moldovan
+rn=Rundi
+ru=Russian
+sg=Sango
+sa=Sanskrit
+si=Sinhala; Sinhalese
+sk=Slovak
+sl=Slovenian
+se=Northern Sami
+sm=Samoan
+sn=Shona
+sd=Sindhi
+so=Somali
+st=Sotho, Southern
+es=Spanish; Castilian
+sq=Albanian
+sc=Sardinian
+sr=Serbian
+ss=Swati
+su=Sundanese
+sw=Swahili
+sv=Swedish
+ty=Tahitian
+ta=Tamil
+tt=Tatar
+te=Telugu
+tg=Tajik
+tl=Tagalog
+th=Thai
+ti=Tigrinya
+to=Tonga (Tonga Islands)
+tn=Tswana
+ts=Tsonga
+tk=Turkmen
+tr=Turkish
+tw=Twi
+ug=Uighur; Uyghur
+uk=Ukrainian
+ur=Urdu
+uz=Uzbek
+ve=Venda
+vi=Vietnamese
+vo=Volapük
+wa=Walloon
+wo=Wolof
+xh=Xhosa
+yi=Yiddish
+yo=Yoruba
+za=Zhuang; Chuang
+zh=Chinese
+zu=Zulu
diff --git a/data/meson.build b/data/meson.build
index 3be4759f..944ffbe3 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -60,5 +60,6 @@ configure_file(
 
 install_data(
   'gtr-plural-forms.ini',
+  'gtr-languages.ini',
   install_dir: join_paths(gtr_pkgdatadir, 'ui'),
 )
diff --git a/meson.build b/meson.build
index d52d8702..c6778bc5 100644
--- a/meson.build
+++ b/meson.build
@@ -104,13 +104,9 @@ src_dir = join_paths(meson.source_root(), 'src')
 glib_dep = dependency('glib-2.0', version: '>= 2.36.0')
 gtk_dep = dependency('gtk+-3.0', version: '>= 3.22.20')
 
-iso_codes_dep = dependency('iso-codes', version: '>= 0.35')
-config_h.set_quoted('PACKAGE_ISO_CODES_PREFIX', iso_codes_dep.get_pkgconfig_variable('prefix'))
-
 gtr_deps = [
   glib_dep,
   gtk_dep,
-  iso_codes_dep,
   dependency('libgda-5.0'),
   dependency('gio-2.0', version: '>= 2.36.0'),
   dependency('gsettings-desktop-schemas'),
@@ -167,4 +163,4 @@ output += '      Development options\n'
 output += '          Enable Debug: ...................: ' + gtr_debug.to_string() + '\n'
 output += '          Enable Documentation: ...........: ' + enable_gtk_doc.to_string() + '\n\n'
 output += '    Now type "ninja -C ' + meson.current_build_dir() + '" to build ' + meson.project_name() + 
'\n\n'
-message(output)
+message(output)
\ No newline at end of file
diff --git a/src/gtr-language.c b/src/gtr-language.c
index 7a08db79..65c679b7 100644
--- a/src/gtr-language.c
+++ b/src/gtr-language.c
@@ -25,15 +25,12 @@
 #endif
 
 #include <glib/gi18n.h>
-#include <libxml/xmlreader.h>
 
 #include "gtr-language.h"
 #include "gtr-dirs.h"
 
-#define ISO_639_DOMAIN "iso_639"
-
-#define ISOCODESLOCALEDIR              PACKAGE_ISO_CODES_PREFIX "/share/locale"
 #define GTR_PLURAL_FORMS_FILENAME      "gtr-plural-forms.ini"
+#define GTR_LANGS_FILENAME     "gtr-languages.ini"
 
 struct _GtrLanguage
 {
@@ -68,20 +65,6 @@ gtr_language_free (GtrLanguage *lang)
   g_return_if_fail (lang != NULL);
 }
 
-static void
-bind_iso_domains (void)
-{
-  static gboolean bound = FALSE;
-
-  if (bound == FALSE)
-    {
-      bindtextdomain (ISO_639_DOMAIN, ISOCODESLOCALEDIR);
-      bind_textdomain_codeset (ISO_639_DOMAIN, "UTF-8");
-
-      bound = TRUE;
-    }
-}
-
 static void
 load_plural_form (GtrLanguage *lang)
 {
@@ -95,34 +78,6 @@ load_plural_form (GtrLanguage *lang)
     lang->plural_form = NULL;
 }
 
-static void
-read_iso_639_entry (xmlTextReaderPtr reader,
-                    GSList **langs)
-{
-  xmlChar *code, *name;
-
-  code = xmlTextReaderGetAttribute (reader, (const xmlChar *) "iso_639_1_code");
-  name = xmlTextReaderGetAttribute (reader, (const xmlChar *) "name");
-
-  if (code != NULL && code[0] != '\0' && name != NULL && name[0] != '\0')
-    {
-      GtrLanguage *lang = g_slice_new (GtrLanguage);
-      lang->code = (gchar *)code;
-      lang->name = g_strdup (dgettext (ISO_639_DOMAIN, (gchar *)name));
-      xmlFree (name);
-
-      /* set the plural form */
-      load_plural_form (lang);
-
-      *langs = g_slist_prepend (*langs, lang);
-    }
-  else
-    {
-      xmlFree (code);
-      xmlFree (name);
-    }
-}
-
 typedef enum
 {
   STATE_START,
@@ -130,84 +85,14 @@ typedef enum
   STATE_ENTRIES
 } ParserState;
 
-static void
-load_iso_entries (int iso,
-                  GFunc read_entry_func,
-                  gpointer user_data)
-{
-  xmlTextReaderPtr reader;
-  ParserState state = STATE_START;
-  xmlChar iso_entries[32], iso_entry[32];
-  char *filename;
-  int ret = -1;
-
-  filename = g_strdup_printf (PACKAGE_ISO_CODES_PREFIX "/share/xml/iso-codes/iso_%d.xml", iso);
-  reader = xmlNewTextReaderFilename (filename);
-  if (reader == NULL)
-    goto out;
-
-  xmlStrPrintf (iso_entries, sizeof (iso_entries), (const char *)"iso_%d_entries", iso);
-  xmlStrPrintf (iso_entry, sizeof (iso_entry), (const char *)"iso_%d_entry", iso);
-
-  ret = xmlTextReaderRead (reader);
-
-  while (ret == 1)
-    {
-      const xmlChar *tag;
-      xmlReaderTypes type;
-
-      tag = xmlTextReaderConstName (reader);
-      type = xmlTextReaderNodeType (reader);
-
-      if (state == STATE_ENTRIES &&
-          type == XML_READER_TYPE_ELEMENT &&
-          xmlStrEqual (tag, iso_entry))
-        {
-          read_entry_func (reader, user_data);
-        }
-      else if (state == STATE_START &&
-               type == XML_READER_TYPE_ELEMENT &&
-               xmlStrEqual (tag, iso_entries))
-        {
-          state = STATE_ENTRIES;
-        }
-      else if (state == STATE_ENTRIES &&
-               type == XML_READER_TYPE_END_ELEMENT &&
-               xmlStrEqual (tag, iso_entries))
-        {
-          state = STATE_STOP;
-        }
-      else if (type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ||
-               type == XML_READER_TYPE_WHITESPACE ||
-               type == XML_READER_TYPE_TEXT ||
-               type == XML_READER_TYPE_COMMENT)
-        {
-          /* eat it */
-        }
-      else
-        {
-          /* ignore it */
-        }
-
-      ret = xmlTextReaderRead (reader);
-    }
-
-  xmlFreeTextReader (reader);
-
-out:
-  if (ret < 0 || state != STATE_STOP)
-    {
-      g_warning ("Failed to load ISO-%d codes from %s!\n",
-                 iso, filename);
-    }
-
-  g_free (filename);
-}
-
 static void
 gtr_language_lazy_init (void)
 {
   gchar *filename;
+  GKeyFile *lang_file;
+  gchar **langs;
+  gchar *lang;
+  gsize n, i;
 
   if (initialized)
     return;
@@ -223,12 +108,34 @@ gtr_language_lazy_init (void)
 
   g_free (filename);
 
-  bind_iso_domains ();
-  load_iso_entries (639, (GFunc) read_iso_639_entry, &languages);
+  lang_file = g_key_file_new ();
+  filename = gtr_dirs_get_ui_file (GTR_LANGS_FILENAME);
+  if (!g_key_file_load_from_file (lang_file, filename, G_KEY_FILE_NONE, NULL))
+    {
+      g_warning ("Bad languages file: '%s'", filename);
+      g_free (filename);
+      return;
+    }
+
+  g_free (filename);
+
+  langs = g_key_file_get_keys (lang_file, "Languages", &n, NULL);
+  for (i=0; i<n; i++)
+    {
+      GtrLanguage *gtr_lang = g_slice_new (GtrLanguage);
+      lang = langs[i];
+      gtr_lang->code = g_strdup (lang);
+      gtr_lang->name = g_key_file_get_string (lang_file, "Languages", lang, NULL);
+      load_plural_form (gtr_lang);
+      languages = g_slist_prepend (languages, gtr_lang);
+    }
+  g_strfreev (langs);
+
   languages = g_slist_reverse (languages);
 
   /* free the file, not needed anymore */
   g_key_file_free (plurals_file);
+  g_key_file_free (lang_file);
 
   initialized = TRUE;
 }


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