bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Correctly extract msgids from entries with msgid_plural


From: Kobayashi Noritada
Subject: Re: [PATCH] Correctly extract msgids from entries with msgid_plural
Date: Sat, 31 May 2008 12:52:19 +0900 (JST)

Hi,

From: Kobayashi Noritada
Subject: [PATCH] Correctly extract msgids from entries with msgid_plural
Date: Thu, 29 May 2008 20:49:44 +0900 (JST)

> po-mode cannot extract correct msgids from entries with msgid_plural.
> When copying msgid to msgstr with C-j (po-msgid-to-msgstr) in such
> entries, msgid_plural fields are regarded as a part of messages and
> copied like this:
> 
> Before:
> 
>   msgid "%d install"
>   msgid_plural "%d installs"
>   msgstr[0] ""
> 
> After:
> 
>   msgid "%d install"
>   msgid_plural "%d installs"
>   msgstr[0] ""
>   "%d install\"\n"
>   "msgid_plural \"%d installs"
> 
> This behavior is caused by po-get-msgid extracting msgid from areas
> between po-start-of-msgstr-form and po-end-of-msgstr-form.  Since
> there are no mechanisms for handling msgid_plurals in po-mode at all,
> I've created a patch to define variables po-start-of-msgid-plural and
> po-any-msgid-plural-msgstr-regexp, adding a support for msgid_plurals
> and fixing this issue.  Could you please find and apply the
> attachment?

I am sorry that the previous patch unfortunately introduces a bug that
entry types are wrongly recognized.  I have fixed that bug with this
patch by changing one line.  Could you please abandon that patch and
check this one?

Many thanks,

-nori
Index: gettext/gettext-tools/misc/po-mode.el
===================================================================
--- gettext.orig/gettext-tools/misc/po-mode.el  2008-05-31 11:30:32.000000000 
+0900
+++ gettext/gettext-tools/misc/po-mode.el       2008-05-31 12:04:20.000000000 
+0900
@@ -687,6 +687,7 @@
 (defvar po-start-of-entry)
 (defvar po-start-of-msgctxt) ; = po-start-of-msgid if there is no msgctxt
 (defvar po-start-of-msgid)
+(defvar po-start-of-msgid-plural) ; = po-start-of-msgstr-block if there is no 
msgid_plural
 (defvar po-start-of-msgstr-block)
 (defvar po-start-of-msgstr-form)
 (defvar po-end-of-msgstr-form)
@@ -1008,6 +1009,10 @@
   "^\\(#~[ \t]*\\)?msgid.*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*"
   "Regexp matching a whole msgid field, whether obsolete or not.")
 
+(defvar po-any-msgid-plural-msgstr-regexp
+  "^\\(#~[ \t]*\\)?msg\\(id_plural\\|str\\).*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*"
+  "Regexp matching a whole msgid_plural or msgstr field, whether obsolete or 
not.")
+
 (defvar po-any-msgstr-block-regexp
   "^\\(#~[ \t]*\\)?msgstr\\([ \t]\\|\\[0\\]\\).*\n\\(\\(#~[ 
\t]*\\)?\".*\n\\)*\\(\\(#~[ \t]*\\)?msgstr\\[[0-9]\\].*\n\\(\\(#~[ 
\t]*\\)?\".*\n\\)*\\)*"
   "Regexp matching a whole msgstr or msgstr[] field, whether obsolete or not.")
@@ -1158,6 +1163,7 @@
   (make-local-variable 'po-start-of-entry)
   (make-local-variable 'po-start-of-msgctxt)
   (make-local-variable 'po-start-of-msgid)
+  (make-local-variable 'po-start-of-msgid-plural)
   (make-local-variable 'po-start-of-msgstr-block)
   (make-local-variable 'po-end-of-entry)
   (make-local-variable 'po-entry-type)
@@ -1399,9 +1405,9 @@
 (defun po-find-span-of-entry ()
   "Find the extent of the PO file entry where the cursor is.
 Set variables PO-START-OF-ENTRY, PO-START-OF-MSGCTXT, PO-START-OF-MSGID,
-po-start-of-msgstr-block, PO-END-OF-ENTRY and PO-ENTRY-TYPE to meaningful
-values. Decreasing priority of type interpretation is: obsolete, fuzzy,
-untranslated or translated."
+PO-START-OF-MSGID-PLURAL, PO-START-OF-MSGSTR-BLOCK, PO-END-OF-ENTRY and
+PO-ENTRY-TYPE to meaningful values. Decreasing priority of type
+interpretation is: obsolete, fuzzy, untranslated or translated."
   (let ((here (point)))
     (if (re-search-backward po-any-msgstr-block-regexp nil t)
         (progn
@@ -1451,13 +1457,16 @@
       (re-search-forward po-any-msgstr-block-regexp)
       (setq po-start-of-msgstr-block (match-beginning 0)
             po-end-of-entry (match-end 0)))
-    ;; Find start of msgid.
+    ;; Find start of msgid and msgid_plural.
     (goto-char po-start-of-entry)
     (re-search-forward po-any-msgctxt-msgid-regexp)
     (setq po-start-of-msgctxt (match-beginning 0))
     (goto-char po-start-of-entry)
     (re-search-forward po-any-msgid-regexp)
     (setq po-start-of-msgid (match-beginning 0))
+    (re-search-forward po-any-msgid-plural-msgstr-regexp)
+    (setq po-start-of-msgid-plural (match-beginning 0))
+    (goto-char po-start-of-msgid)
     (save-excursion
       (when (>= here po-start-of-msgstr-block)
         ;; point was somewhere inside of msgstr*
@@ -1888,7 +1897,7 @@
   "Extract and return the unquoted msgid string."
   (let ((string (po-extract-unquoted (current-buffer)
                                      po-start-of-msgid
-                                     po-start-of-msgstr-block)))
+                                     po-start-of-msgid-plural)))
     string))
 
 (defun po-get-msgstr-flavor ()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]