GNOME Bugzilla – Bug 131505
intltool should support translator comments in xml files
Last modified: 2004-12-22 21:47:04 UTC
xgettext has a nice feature for automatically extracting comments, usually aimed for translators, into the po files. Please see http://developer.gnome.org/doc/tutorials/gnome-i18n/developer.html#use-comments. This is sometimes essential for translators to be able to translate some things correctly, and it is much needed also in other formats such as schema files and XML files in general. Hence, intltool should probably be capable of automatically extracting such comments out of XML files and placing them as translator comments in the pot/po files.
Yeah, we really need this. e.g. in GConf schemas you might have <locale name="C"> <default>24-hour</default> ... </locale> and you really, really want to be able to do: <locale name="C"> <!-- Translators: the only valid value for this are "12-hour" or "24-hour" --> <default>24-hour</default> ... </locale>
I've started that discussion in January, along with the patch. http://pdx.freedesktop.org/pipermail/intltool/2004-January/000001.html It was only for bare XML files (not .schemas files), but I've just updated it for them as well. The core of the patch is changed regular expression which extracts the comment, if any. One debatable point I decided on was that I required the comment to be followed with at least one newline (\n). I'm not sure if that's good or not, but it's easily changed (the idea was to extract comment from "previous line"; if "\n" is followed by a "?", we'd get "this or previous line" instead). I'll attach the patch here, along with README file update (README update would make even more sense if certain string was chosen to indicate that a comment really needs to be output, like "i18n:" or "translators:"). What blocked the patch at that time was that I didn't provide any tests (and with current tests in intltool being seriously messed up, it's even harder to do it, since they need to be rechecked completely), and that we should instead switch to XML::Parser even in these cases (this is something I strongly object, but this is not the place nor time for that discussion :). One useful addition mentioned in the linked discussion was usage of specially formated comment, instead of "any comment". The proposal was to use "i18n:" string to start such comments, and that can be easily changed with current patch. Since .schemas files are treated specially, I think it might be nice to insert some kind of comment for <default> values in all cases: they're usually expected to be of certain form, and rarely do they need to be translated directly (more commonly, they need to be chosen from a set of predefined values). I propose to do it with the comment like "Translators: this is default value for a GConf setting. Be careful when translating." Of course, when there already is an author-provided comment, we would not output this one. Please comment on the patch, and other ideas.
Created attachment 26368 [details] [review] Extract comments for translators for XML and .schemas files
Danilo you are my very personal hero! :) regs, Chris
The patch looks fine. If you add a test you can commit.
I'll modify test.schemas.in (which currently fails anyway, because of move from []-style comments in schemas) with the following simple change: --- results/test.schemas Wed Oct 16 16:13:46 2002 +++ cases/test.schemas Fri Apr 9 23:53:08 2004 @@ -7,13 +7,16 @@ <owner>clock-applet</owner> <type>int</type> <locale name="C"> - <default>24</default> + <default><!-- default value for /schemas/apps/clock_applet/prefs/hour_format + The translation should only include the localized default + eg. 12 or 24 --> + 24</default> <short>Hour format</short> <long>Sets the hour format, may be either 12 or 24</long> </locale> <locale name="schemasmerge1"> - <default>12</default> + <short>Timformat</short> <long>Ställer in formatet på timmar, kan vara antingen 12 eller 24</long> </locale> --- results/test.schemas.in.h Thu Oct 3 16:21:31 2002 +++ cases/test.schemas.in.h Fri Apr 9 23:53:08 2004 @@ -1,7 +1,10 @@ char *s = N_("12"); +/* default value for /schemas/apps/clock_applet/prefs/hour_format + The translation should only include the localized default + eg. 12 or 24 */ +char *s = N_("24"); char *s = N_("Display seconds in time"); char *s = N_("Hour format"); char *s = N_("Puh long."); char *s = N_("Sets the hour format, may be either 12 or 24"); char *s = N_("Something random..even has >"); -char *s = N_("[default value for /schemas/apps/clock_applet/prefs/hour_format The translation should only include the localized default eg. 12 or 24 ]24"); I've made a separate test for general XML comments handling. It tries to go through some corner-cases.
Just another note, I'll commit this with appropriate tests one of these days (I'll be out for a weekend, but I might be able to get Internet access during this time).
Did you commit this yet?
Hi all, sorry for not responding earlier, I was out of town. This wasn't commited yet, because I found a bug when going through more testing, but didn't have the time to mention it since I was going away. The new patch requires the comment *not* to contain ">" in it, or it will not detect it. This means that some comments won't work, but it's still better than what we have now. I'll mention that in README as well. There's a testcase to check for this as well. I have committed the following patch now. The bulk of the patch are testcases, and it's otherwise same as the previous (that's why I went ahead and committed it).
Comment on attachment 26368 [details] [review] Extract comments for translators for XML and .schemas files This one is obsolete now.
Created attachment 27435 [details] [review] Support for comments in XML files (with testcases) I've committed this patch to CVS HEAD.
Everyone, please test this now, and reopen if I made a mistake somewhere. Sorry again for being so slow on this.