[gnome-desktop/wip/locale-info: 5/11] Add default input sources per locale
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop/wip/locale-info: 5/11] Add default input sources per locale
- Date: Sun, 10 Feb 2013 01:35:47 +0000 (UTC)
commit 839aa0c193fd6ecf61634ee53216dca588feb64c
Author: Rui Matos <tiagomatos gmail com>
Date: Tue Jan 29 14:53:37 2013 +0100
Add default input sources per locale
This will allow us to have good defaults so that we don't have to
bother asking the user something that we can derive from the chosen
locale.
libgnome-desktop/Makefile.am | 1 +
libgnome-desktop/default-input-sources.h | 52 ++++++++++++++++++++++++++
libgnome-desktop/gnome-languages.c | 58 ++++++++++++++++++++++++++++++
libgnome-desktop/gnome-languages.h | 3 ++
4 files changed, 114 insertions(+), 0 deletions(-)
---
diff --git a/libgnome-desktop/Makefile.am b/libgnome-desktop/Makefile.am
index 4417f7d..e2b57c1 100644
--- a/libgnome-desktop/Makefile.am
+++ b/libgnome-desktop/Makefile.am
@@ -45,6 +45,7 @@ libgnome_desktop_3_la_SOURCES = \
gnome-datetime-source.h \
gnome-datetime-source.c \
gnome-rr-private.h \
+ default-input-sources.h \
edid.h \
locarchive.h \
private.h
diff --git a/libgnome-desktop/default-input-sources.h b/libgnome-desktop/default-input-sources.h
new file mode 100644
index 0000000..b055cbe
--- /dev/null
+++ b/libgnome-desktop/default-input-sources.h
@@ -0,0 +1,52 @@
+typedef struct
+{
+ const gchar const *locale;
+ const gchar const *type;
+ const gchar const *id;
+} DefaultInputSource;
+
+static DefaultInputSource default_input_sources[] =
+{
+ { "ar_DZ", "xkb", "ara+azerty" },
+ { "as_IN", "ibus", "m17n:as:phonetic" },
+ { "ast_ES", "xkb", "es+ast" },
+ { "az_AZ", "xkb", "az" },
+ { "be_BY", "xkb", "by" },
+ { "bn_IN", "ibus", "m17n:bn:inscript" },
+ { "cat_ES", "xkb", "es+cat" },
+ { "cs_CZ", "xkb", "cz" },
+ { "de_DE", "xkb", "de" },
+ { "el_CY", "xkb", "gr" },
+ { "el_GR", "xkb", "gr" },
+ { "en_GB", "xkb", "gb" },
+ { "en_US", "xkb", "us" },
+ { "es_ES", "xkb", "es" },
+ { "fr_FR", "xkb", "fr+oss" },
+ { "gl_ES", "xkb", "es" },
+ { "gu_IN", "ibus", "m17n:gu:inscript" },
+ { "he_IL", "xkb", "il" },
+ { "hi_IN", "ibus", "m17n:hi:inscript" },
+ { "it_IT", "xkb", "it" },
+ { "ja_JP", "ibus", "anthy" },
+ { "kn_IN", "ibus", "m17n:kn:kgp" },
+ { "ko_KR", "ibus", "hangul" },
+ { "mai_IN", "ibus", "m17n:mai:inscript" },
+ { "ml_IN", "ibus", "m17n:ml:inscript" },
+ { "mr_IN", "ibus", "m17n:mr:inscript" },
+ { "nl_NL", "xkb", "us+altgr-intl" },
+ { "or_IN", "ibus", "m17n:or:inscript" },
+ { "pa_IN", "ibus", "m17n:pa:inscript" },
+ { "pl_PL", "xkb", "pl" },
+ { "pt_BR", "xkb", "br" },
+ { "pt_PT", "xkb", "pt" },
+ { "ru_RU", "xkb", "ru" },
+ { "sd_IN", "ibus", "m17n:sd:inscript" },
+ { "sk_SK", "xkb", "sk" },
+ { "ta_IN", "ibus", "m17n:ta:tamil99" },
+ { "te_IN", "ibus", "m17n:te:inscript" },
+ { "ur_IN", "ibus", "m17n:ur:phonetic" },
+ { "zh_CN", "ibus", "libpinyin" },
+ { "zh_HK", "ibus", "cangjie" },
+ { "zh_TW", "ibus", "chewing" },
+ { NULL, NULL, NULL }
+};
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index c3d3775..d774263 100644
--- a/libgnome-desktop/gnome-languages.c
+++ b/libgnome-desktop/gnome-languages.c
@@ -51,6 +51,8 @@
#define ISO_CODES_DATADIR ISO_CODES_PREFIX "/share/xml/iso-codes"
#define ISO_CODES_LOCALESDIR ISO_CODES_PREFIX "/share/locale"
+#include "default-input-sources.h"
+
typedef struct _GnomeLocale {
char *id;
char *name;
@@ -1349,3 +1351,59 @@ gnome_get_country_from_code (const char *code,
return get_translated_territory (code, locale);
}
+
+/**
+ * gnome_get_input_source_from_locale:
+ * @locale: a locale string
+ * @type: (out) (transfer none): location to store the input source
+ * type
+ * @id: (out) (transfer none): location to store the input source
+ * identifier
+ *
+ * Gets the default input source's type and identifier for a given
+ * locale.
+ *
+ * Return value: %TRUE if a input source exists or %FALSE otherwise.
+ *
+ * Since: 3.8
+ */
+gboolean
+gnome_get_input_source_from_locale (const char *locale,
+ const char **type,
+ const char **id)
+{
+ static GHashTable *table = NULL;
+ DefaultInputSource *dis;
+ gchar *l_code, *c_code;
+ gchar *key;
+ gint i;
+
+ g_return_val_if_fail (locale != NULL, FALSE);
+ g_return_val_if_fail (type != NULL, FALSE);
+ g_return_val_if_fail (id != NULL, FALSE);
+
+ if (!table) {
+ table = g_hash_table_new (g_str_hash, g_str_equal);
+ for (i = 0; default_input_sources[i].id; ++i) {
+ dis = &default_input_sources[i];
+ g_hash_table_insert (table, (gpointer) dis->locale, dis);
+ }
+ }
+
+ if (!gnome_parse_language_name (locale, &l_code, &c_code, NULL, NULL))
+ return FALSE;
+
+ key = g_strconcat (l_code, "_", c_code, NULL);
+
+ dis = g_hash_table_lookup (table, key);
+ if (dis) {
+ *type = dis->type;
+ *id = dis->id;
+ }
+
+ g_free (l_code);
+ g_free (c_code);
+ g_free (key);
+
+ return dis != NULL;
+}
diff --git a/libgnome-desktop/gnome-languages.h b/libgnome-desktop/gnome-languages.h
index 6b28b85..e08e410 100644
--- a/libgnome-desktop/gnome-languages.h
+++ b/libgnome-desktop/gnome-languages.h
@@ -46,6 +46,9 @@ char * gnome_get_language_from_code (const char *code,
const char *locale);
char * gnome_get_country_from_code (const char *code,
const char *locale);
+gboolean gnome_get_input_source_from_locale (const char *locale,
+ const char **type,
+ const char **id);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]