[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gettext] Glade/GtkBuilder related bugs
From: |
Miguel Ángel |
Subject: |
Re: [bug-gettext] Glade/GtkBuilder related bugs |
Date: |
Wed, 30 Jan 2013 11:36:38 +0100 |
Hi,
El mié, 30-01-2013 a las 16:38 +0900, Daiki Ueno escribió:
> Hi,
>
> Miguel Ángel <address@hidden> writes:
>
> > I have sent a patch for the bug #34506 that solves the "context"
> > problem, but I think that is a first approach, because it looks for it
> > in every tag.
>
> Thanks for the patch. A comment and a revised patch are below.
Thank you very much for revising the patch. But actually this patch is
more a workaround than solving the bug, see below. Sorry.
>
> > I will thank any advices if I have to sign anything to contribute with a
> > bigger code. I also could help with the refactor of other parsers that I
> > have seen you are going to do.
>
> Thanks for your interest. I'll send you the details privately.
>
> > /* Callback called when <element> is seen. */
> > static void
> > start_element_handler (void *userData, const char *name,
> > @@ -429,6 +450,7 @@ start_element_handler (void *userData, const char *name,
> > p = &stack[stack_depth];
> > p->extract_string = extract_all;
> > p->extracted_comment = NULL;
> > + p->extracted_context = extract_context (attributes);
>
> Do we really need to extract "context" attribute from every element?
> Otherwise, I guess it can be folded in the while-loop below to extract
> the translator comments.
>
My second patch points this, but that is not the issue. Actually there
is a problem, I pointed it out at the next mail of my pile in
bug-gettext archive ;-). Glade2 and GtkBuilder are not compatible. The
first one have in the context attribute "yes" or "no" and the string
have the Glib syntax "msgctxt|msgid". The second one has msgctxt in the
context attribute.
> From 6453b69251484860e487e2190be6f5b7b595b124 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
> <address@hidden>
> Date: Wed, 30 Jan 2013 16:21:50 +0900
> Subject: [PATCH] Extract message contexts from Glade input files.
>
> ---
> gettext-tools/src/ChangeLog | 8 ++++++++
> gettext-tools/src/x-glade.c | 12 +++++++++++-
> 2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
> index 68da6a6..565e62a 100644
> --- a/gettext-tools/src/ChangeLog
> +++ b/gettext-tools/src/ChangeLog
> @@ -1,3 +1,11 @@
> +2013-01-30 Miguel Ángel Arruga Vivas <address@hidden> (tiny change)
> +
> + Extract message contexts from Glade input files.
> + Reported at <https://savannah.gnu.org/bugs/?34506>
> + * x-glade.c (struct element_state): Add field 'extracted_context'.
> + (start_element_handler): Extract "context" attribute.
> + (end_element_handler): Respect p->extracted_context.
> +
> 2013-01-09 Andreas Stricker <address@hidden> (tiny change)
>
> * po-xerror.c: Include error.h for error_message_count.
> diff --git a/gettext-tools/src/x-glade.c b/gettext-tools/src/x-glade.c
> index 11f8397..e3167c5 100644
> --- a/gettext-tools/src/x-glade.c
> +++ b/gettext-tools/src/x-glade.c
> @@ -386,6 +386,7 @@ struct element_state
> {
> bool extract_string;
> char *extracted_comment;
> + char *extracted_context;
> int lineno;
> char *buffer;
> size_t bufmax;
> @@ -429,6 +430,7 @@ start_element_handler (void *userData, const char *name,
> p = &stack[stack_depth];
> p->extract_string = extract_all;
> p->extracted_comment = NULL;
> + p->extracted_context = NULL;
> /* In Glade 1, a few specific elements are translatable. */
> if (!p->extract_string)
> p->extract_string =
> @@ -444,6 +446,7 @@ start_element_handler (void *userData, const char *name,
> {
> bool has_translatable = false;
> const char *extracted_comment = NULL;
> + const char *extracted_context = NULL;
> const char **attp = attributes;
> while (*attp != NULL)
> {
> @@ -451,6 +454,8 @@ start_element_handler (void *userData, const char *name,
> has_translatable = (strcmp (attp[1], "yes") == 0);
> else if (strcmp (attp[0], "comments") == 0)
> extracted_comment = attp[1];
> + else if (strcmp (attp[0], "context") == 0)
> + extracted_context = attp[1];
> attp += 2;
> }
> p->extract_string = has_translatable;
> @@ -458,6 +463,10 @@ start_element_handler (void *userData, const char *name,
> (has_translatable && extracted_comment != NULL
> ? xstrdup (extracted_comment)
> : NULL);
> + p->extracted_context =
> + (has_translatable && extracted_context != NULL
> + ? xstrdup (extracted_context)
> + : NULL);
> }
> if (!p->extract_string
> && strcmp (name, "atkaction") == 0)
> @@ -512,7 +521,8 @@ end_element_handler (void *userData, const char *name)
> pos.file_name = logical_file_name;
> pos.line_number = p->lineno;
>
> - remember_a_message (mlp, NULL, p->buffer, null_context, &pos,
> + remember_a_message (mlp, p->extracted_context, p->buffer,
> + null_context, &pos,
> p->extracted_comment, savable_comment);
> p->buffer = NULL;
> }
I have already a functional xgettext with GtkBuilder support and Glade
fixed, but the implementation is not a simple patch. The new tests are
almost copied from existing xgettext-* tests, but filled with new data,
and I have extended xgettext-glade-4 also. You can see it at
https://github.com/644rosen/gettext_gtkbuilder_support.git
or I could send you the patches by mail to save effort. "glade_bugs"
branch fixes Glade support (also a couple of xgettext leaks) and
"gtkbuilder" branch adds GtkBuilder support to x-glade.{c,h}. I try to
separate it (that is why I created "libexpat_extraction" branch at first
place), but there is so much common code, almost every piece of it can
be shared, that I used function pointers to hook code for each type of
file and I forgot splitting it, but I could done it this way if you want
to.
Happy hacking! :)
Miguel
- [bug-gettext] Glade/GtkBuilder related bugs, Miguel Ángel, 2013/01/25
- Re: [bug-gettext] Glade/GtkBuilder related bugs, Daiki Ueno, 2013/01/30
- Re: [bug-gettext] Glade/GtkBuilder related bugs,
Miguel Ángel <=
- Re: [bug-gettext] Glade/GtkBuilder related bugs, Daiki Ueno, 2013/01/30
- [bug-gettext] [Patch 1/1] Savannah bug #36063, Miguel Ángel, 2013/01/31
- Re: [bug-gettext] Glade/GtkBuilder related bugs, Miguel Ángel, 2013/01/31
- [bug-gettext] [Patch 1/2] Glade/GtkBuilder related bugs, Miguel Ángel, 2013/01/31
- Re: [bug-gettext] [Patch 2/2] Glade/GtkBuilder related bugs, Miguel Ángel, 2013/01/31