Yii Framework Forum: I18N And Gettext - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

I18N And Gettext Problem with I18n with PO or MO files Rate Topic: -----

#1 User is offline   RandomWhiteTrash 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 05-October 11

Posted 30 January 2013 - 02:40 AM

Hi guys,

Its either that I dont understand something or my PO files are somehow wrong or something else is wrong...

What is happening is - I want to use po or mo files for i18n. I used yiic message to export php files and then converted them with POPHPcommand to .po files.
So far so good.

However, then when I switch my message class to CGettextMessageSource nothing happens i.e. whatever I translate using say POEdit does not appear onthe page.

I have visited CGettextMessageSource and CGettextPoFile classes and noticed that CGettextMessageSource has a public property $catalog. This is then used to load a file like this:

    protected function loadMessages($category, $language)
    {
        $messageFile = $this->basePath . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $this->catalog;


So for the sake of argument the name of the file will always be ... $this->catalog . ".po" = ..../message.po (Just to make sure you know I am not totally confused, I know that I can change that when I instantiate the class but it still would allow me to use one file at a time only, while I would like to use two - say 'frontend' and 'common' i.e.
<?=Yii::t('frontend','Something');?><br/>
<?=Yii::t('common','ok');?>

).

But if I am using differnet categories of messages then I do not have message.po but frontend.po and backend.po.... This is what yiic messages genarates for Yii:t('frontend','My message');

Then in CGettextPoFile there is a conditional
 if ($matches[2][$i] === $context) {
...
}

where $context is a a value of $category ('frontend','backend')... therefore it stipulates that inside the po file there is a separation into categories (which CGettextMessageSource calls $this->catalog). According to CGettextPoFile .po file should look like this:
msgctxt "frontend"
msgid "Accounts"
msgstr "Konta"


Why is this so? I never saw any 'category' (or msgctxt) distinction in any of the po files, whether I created it with yii or POEdit. Plus it really does not make sense to create categories in one file, right? Whole point of messages separation is to load smaller files and avoid loading of unnecesary translations to save resources, right?

If I were to change $this->catalog to $category in CGettextMessageSource and comment/remove this conditional in CGettextPoFile suddenly my po files start to work...

Now I dont want to modify the framework or unnecesarily extend the classes, so please tell me, why is this done like this and how should I get it to work without modifying framework files?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users