Re: [MKDoc-dev] [BUG] I18NFool clobbers things with the same key

Bruno Postle <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.petal,gmane.comp.cms.mkdoc.devel
Message-ID <[email protected]>
Not sure which list this should go to, but the I18NFool translation 
stuff is as much related to internationalising Petal templates as 
the current task of translating the MKDoc interface.

Attached, a patch that adds some suitable warnings when running 
i18nfool-extract.

I released I18NFool-0.3 yesterday with some accumulated bugfixes, I 
guess I could release again.

On Wed 06-Oct-2004 at 15:04 +0100, Chris Croome wrote:
>
> If you have something like this in the templates:
>
>  <p
>    i18n:translate="foo"
>  >Foo</p>
>
>  <p
>    i18n:translate="foo"
>  >Bar</p>
>
> Then rather than warning you that the first value of foo is going to be
> replaced with the second I18NFool just clobbers the first value...

Chris' test is here:

  http://lists.webarch.co.uk/pipermail/mkdoc-dev/2004-October/000059.html

-- 
Bruno
i18nfool-warn-when-clobbering-non-matching-strings.patch (text/plain, 1.9 KB)
diff -Nbaur -x CVS I18NFool-0.3/lib/I18NFool/Extractor.pm /home/bruno/src/cvs/I18NFool/lib/I18NFool/Extractor.pm
--- I18NFool-0.3/lib/I18NFool/Extractor.pm	2004-10-06 12:21:34.000000000 +0100
+++ /home/bruno/src/cvs/I18NFool/lib/I18NFool/Extractor.pm	2004-10-07 10:29:48.000000000 +0100
@@ -83,10 +83,21 @@
 
             $translate_id || next;
             $Results->{$Domain} ||= {};
-            $Results->{$Domain}->{$translate_id} = Locale::PO->new (
+
+            my $existing_po = $Results->{$Domain}->{$translate_id};
+            my $new_po = Locale::PO->new (
                 -msgid  => $translate_id,
                 -msgstr => _canonicalize ( $tree->{$attribute_name} ) || '',
             );
+
+            if ($existing_po && ($existing_po->{msgstr} ne $new_po->{msgstr}))
+            {
+                print STDERR "String for '$translate_id' doesn't match:\n".
+                             "   old: $existing_po->{msgstr}\n".
+                             "   new: $new_po->{msgstr}\n"
+            }
+
+            $Results->{$Domain}->{$translate_id} = $new_po;
         }
     };
 
@@ -112,10 +123,21 @@
 
         $translate_id || next;
         $Results->{$Domain} ||= {};
-        $Results->{$Domain}->{$translate_id} = Locale::PO->new (
+
+        my $existing_po = $Results->{$Domain}->{$translate_id};
+        my $new_po = Locale::PO->new (
             -msgid  => $translate_id,
             -msgstr => _canonicalize ( _extract_content_string ($tree) ) || '',
         );
+
+        if ($existing_po && ($existing_po->{msgstr} ne $new_po->{msgstr}))
+        {
+            print STDERR "String for '$translate_id' doesn't match:\n".
+                         "   old: $existing_po->{msgstr}\n".
+                         "   new: $new_po->{msgstr}\n"
+        }
+
+        $Results->{$Domain}->{$translate_id} = $new_po;
     };
 
     # I know, I know, the I18N namespace processing is a bit broken...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.