JaquelineBrandao / yii

Automatically exported from code.google.com/p/yii
0 stars 0 forks source link

Get text message does not parse the PO files #957

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the gettext message source
2. Add a new PO file
3. Use the  load() method in the CGettextPoFile class to load the strings
from a PO file

What is the expected output? 
an array containing all the keys and strings key => string

What do you see instead?
nothing, returns null

What version of the product are you using? 
1.1

On what operating system?
Linux, Ubuntu 9.10

Please provide any additional information below.

Original issue reported on code.google.com by vadimg88@gmail.com on 24 Feb 2010 at 7:53

GoogleCodeExporter commented 9 years ago
Could you please provide the code and the PO file that can reproduce the issue? 
Thanks.

Original comment by qiang.xue on 26 Feb 2010 at 3:04

GoogleCodeExporter commented 9 years ago
The problem is that the current regex looks for message context (msgctxt) in 
every
"record" like

msgctxt ""
msgid "Hello"
msgstr "REPLACED"

msgctxt ""
msgid "Hello2"
msgstr "REPLACED2"

So the regex should be changed so that the context msgctxt is optional 
(enclosed in (
... )? in the regex) and the $matches index should be set appropriately...

here is the new load() function that works:
public function load($file,$context)
    {
                $pattern='/(msgctxt\s+"(.*?(?<!\\\\))")?'
                        . '\s+msgid\s+"(.*?(?<!\\\\))"'
                        . '\s+msgstr\s+"(.*?(?<!\\\\))"/';
        $content=file_get_contents($file);
        $n=preg_match_all($pattern,$content,$matches);
        $messages=array();
        for($i=0;$i<$n;++$i)
        {
            if($matches[2][$i]===$context)
            {
                $id=$this->decode($matches[3][$i]);
                $message=$this->decode($matches[4][$i]);
                $messages[$id]=$message;
            }
        }
        return $messages;
    }

PO file specification say that the msgctxt is optional... in Yii this is used 
for the
context... so if you are using translations for different contexts than you 
should
use the msgctxt on every record in this implementation as it is now...

Original comment by vadimg88@gmail.com on 26 Feb 2010 at 4:11

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1845.

Original comment by qiang.xue on 27 Feb 2010 at 1:11

GoogleCodeExporter commented 9 years ago
Thanks!

Original comment by qiang.xue on 27 Feb 2010 at 1:12