[totem] Use GstTag library to translate subtitle languages
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] Use GstTag library to translate subtitle languages
- Date: Tue, 6 Apr 2010 17:09:03 +0000 (UTC)
commit 5ecafddf9438a1189c966932009fab64f84dfeb1
Author: Bastien Nocera <hadess hadess net>
Date: Tue Apr 6 17:08:02 2010 +0100
Use GstTag library to translate subtitle languages
Instead of implementing iso-codes parsing ourselves.
https://bugzilla.gnome.org/show_bug.cgi?id=614976
configure.in | 30 +----------
src/totem-menu.c | 154 +-----------------------------------------------------
2 files changed, 3 insertions(+), 181 deletions(-)
---
diff --git a/configure.in b/configure.in
index d48723c..495ed05 100644
--- a/configure.in
+++ b/configure.in
@@ -147,30 +147,6 @@ do
fi
done
-AC_MSG_CHECKING([Whether not to check for iso-codes])
-AC_ARG_ENABLE([iso-codes],
- AS_HELP_STRING([--disable-iso-codes],[Whether not to check for iso-codes at build-time]),
- [],[disable_iso_codes_check=no])
-if test x$disable_iso_codes_check = xno ; then
- AC_MSG_RESULT([no])
-else
- AC_MSG_RESULT([yes])
-fi
-
-if test x$disable_iso_codes_check = "xno" ; then
- AC_MSG_CHECKING([whether iso-codes has iso-639 domain])
- if $PKG_CONFIG --variable=domains iso-codes | grep 639 >/dev/null ; then
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no])
- fi
- AC_DEFINE_UNQUOTED([ISO_CODES_PREFIX],["`$PKG_CONFIG --variable=prefix iso-codes`"],[ISO codes prefix])
- ISO_CODES=iso-codes
-else
- AC_DEFINE_UNQUOTED([ISO_CODES_PREFIX],["$prefix"],[ISO codes prefix])
- ISO_CODES=""
-fi
-
dnl Check the smclient backend
GDK_TARGET="$($PKG_CONFIG --variable target gdk-2.0)"
@@ -205,6 +181,7 @@ PKG_CHECK_MODULES([DEPENDENCY],[
gmodule-2.0
gconf-2.0
totem-plparser >= $TOTEM_PLPARSER_REQS
+ gstreamer-tag-0.10 >= 0.10.26
cairo])
PKG_CHECK_MODULES(MM, $MM)
@@ -920,11 +897,6 @@ if test x$ENABLE_NAUTILUS = xyes ; then
else
AC_MSG_NOTICE([ Nautilus properties page disabled])
fi
-if test x$disable_iso_codes_check = xno ; then
- AC_MSG_NOTICE([** iso-codes support checked])
-else
- AC_MSG_NOTICE([ iso-codes support checked at run-time])
-fi
if test x$enable_xtest = xyes ; then
AC_MSG_NOTICE([** XTest (legacy screensaver) support enabled])
else
diff --git a/src/totem-menu.c b/src/totem-menu.c
index 044f01a..5d977cd 100644
--- a/src/totem-menu.c
+++ b/src/totem-menu.c
@@ -24,6 +24,7 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
+#include <gst/tag/tag.h>
#include <string.h>
#include "totem-menu.h"
@@ -93,157 +94,6 @@ escape_label_for_menu (const char *name)
return new;
}
-/* ISO-639 helpers */
-static GHashTable *lang_table;
-
-static void
-totem_lang_table_free (void)
-{
- g_hash_table_destroy (lang_table);
- lang_table = NULL;
-}
-
-static void
-totem_lang_table_parse_start_tag (GMarkupParseContext *ctx,
- const gchar *element_name,
- const gchar **attr_names,
- const gchar **attr_values,
- gpointer data,
- GError **error)
-{
- const char *ccode_longB, *ccode_longT, *ccode, *lang_name;
-
- if (!g_str_equal (element_name, "iso_639_entry")
- || attr_names == NULL
- || attr_values == NULL)
- return;
-
- ccode = NULL;
- ccode_longB = NULL;
- ccode_longT = NULL;
- lang_name = NULL;
-
- while (*attr_names && *attr_values)
- {
- if (g_str_equal (*attr_names, "iso_639_1_code"))
- {
- /* skip if empty */
- if (**attr_values)
- {
- g_return_if_fail (strlen (*attr_values) == 2);
- ccode = *attr_values;
- }
- } else if (g_str_equal (*attr_names, "iso_639_2B_code")) {
- /* skip if empty */
- if (**attr_values)
- {
- g_return_if_fail (strlen (*attr_values) == 3 || strcmp (*attr_values, "qaa-qtz") == 0);
- ccode_longB = *attr_values;
- }
- } else if (g_str_equal (*attr_names, "iso_639_2T_code")) {
- /* skip if empty */
- if (**attr_values)
- {
- g_return_if_fail (strlen (*attr_values) == 3 || strcmp (*attr_values, "qaa-qtz") == 0);
- ccode_longT = *attr_values;
- }
- } else if (g_str_equal (*attr_names, "name")) {
- lang_name = *attr_values;
- }
-
- ++attr_names;
- ++attr_values;
- }
-
- if (lang_name == NULL)
- return;
-
- if (ccode != NULL)
- {
- g_hash_table_insert (lang_table,
- g_strdup (ccode),
- g_strdup (lang_name));
- }
- if (ccode_longB != NULL)
- {
- g_hash_table_insert (lang_table,
- g_strdup (ccode_longB),
- g_strdup (lang_name));
- }
- if (ccode_longT != NULL)
- {
- g_hash_table_insert (lang_table,
- g_strdup (ccode_longT),
- g_strdup (lang_name));
- }
-}
-
-#define ISO_CODES_DATADIR ISO_CODES_PREFIX"/share/xml/iso-codes"
-#define ISO_CODES_LOCALESDIR ISO_CODES_PREFIX"/share/locale"
-
-static void
-totem_lang_table_init (void)
-{
- GError *err = NULL;
- char *buf;
- gsize buf_len;
-
- lang_table = g_hash_table_new_full
- (g_str_hash, g_str_equal, g_free, g_free);
-
- g_atexit (totem_lang_table_free);
-
- bindtextdomain ("iso_639", ISO_CODES_LOCALESDIR);
- bind_textdomain_codeset ("iso_639", "UTF-8");
-
- if (g_file_get_contents (ISO_CODES_DATADIR "/iso_639.xml",
- &buf, &buf_len, &err))
- {
- GMarkupParseContext *ctx;
- GMarkupParser parser =
- { totem_lang_table_parse_start_tag, NULL, NULL, NULL, NULL };
-
- ctx = g_markup_parse_context_new (&parser, 0, NULL, NULL);
-
- if (!g_markup_parse_context_parse (ctx, buf, buf_len, &err))
- {
- g_warning ("Failed to parse '%s': %s\n",
- ISO_CODES_DATADIR"/iso_639.xml",
- err->message);
- g_error_free (err);
- }
-
- g_markup_parse_context_free (ctx);
- g_free (buf);
- } else {
- g_warning ("Failed to load '%s': %s\n",
- ISO_CODES_DATADIR"/iso_639.xml", err->message);
- g_error_free (err);
- }
-}
-
-static const char *
-totem_lang_get_full (const char *lang)
-{
- const char *lang_name;
- int len;
-
- g_return_val_if_fail (lang != NULL, NULL);
-
- len = strlen (lang);
- if (len != 2 && len != 3)
- return NULL;
- if (lang_table == NULL)
- totem_lang_table_init ();
-
- lang_name = (const gchar*) g_hash_table_lookup (lang_table, lang);
-
- if (lang_name)
- return dgettext ("iso_639", lang_name);
-
- return NULL;
-}
-
/* Subtitle and language menus */
static void
totem_g_list_deep_free (GList *list)
@@ -289,7 +139,7 @@ add_lang_action (Totem *totem, GtkActionGroup *action_group, guint ui_id,
GtkAction *action;
guint i;
- full_lang = totem_lang_get_full (lang);
+ full_lang = gst_tag_get_language_name (lang);
if (lang_index > 1) {
char *num_lang;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]