How to generate a gettext source file

View: New views
6 Messages — Rating Filter:   Alert me  

How to generate a gettext source file

by Vincent T :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

First of all: I'm completely new to generating gettext source files and relatively new to the Zend Framework and OOP too.

I currently use revision 7199 if it's of any relevance.

Now, I've made a view helper to return a Zend_Translate object, see below.
Then in my view file I call "echo $this->translate()->_('Test');". Now I want to generate a source file using poEdit, however, it doesn't seem to find any strings. What am I doing wrong?

My view helper:

class Zend_View_Helper_Translate
{
    public static $translate;

    public function translate()
    {
        if(!isset($this->translate))
        {
            $i18nConfig = new Zend_Config_Ini('application/config.ini', 'i18n');
            $this->translate = new Zend_Translate('gettext', $i18nConfig->path, 'en');
        }
        return $this->translate;
    }
}


Thanks in advance,
--
Vincent

How to generate a gettext source file

by Vincent T :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,

First of all: I'm completely new to generating gettext source files and relatively new to the Zend Framework and OOP too.

I currently use revision 7199 if it's of any relevance.

Now, I've made a view helper to return a Zend_Translate object, see below.
Then in my view file I call "echo $this->translate()->_('Test');". Now I want to generate a source file using poEdit, however, it doesn't seem to find any strings. What am I doing wrong?

My view helper:

class Zend_View_Helper_Translate
{
    public static $translate;

    public function translate()
    {
        if(!isset($this->translate))
        {
            $i18nConfig = new Zend_Config_Ini('application/config.ini', 'i18n');
            $this->translate = new Zend_Translate('gettext', $i18nConfig->path, 'en');
        }
        return $this->translate;
    }
}


Thanks in advance,
--
Vincent

Re: How to generate a gettext source file

by thomasW :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ZF and poEdit are not related together.
They are two completly different products.

You will first have to create a translation source.
How you do this is on you... you can use poEdit or any other program for
this task.

Generally your problem is poEdit and not the framework.
Just set your poEdit to search for the right function.

Normally gettext (for which poEdit was created) uses a function "gettext()"
for translation.
But you are using the abbreviation which you have not said poEdit to search
for.

Solution:
Just set poEdit to search for the method "_" which you are using, and it
will work.

Greetings
Thomas
I18N Team Leader

----- Original Message -----
From: "Vincent" <imnotb@...>
To: <fw-i18n@...>
Sent: Friday, December 21, 2007 1:47 PM
Subject: [fw-i18n] How to generate a gettext source file


> Hello,
>
> First of all: I'm completely new to generating gettext source files and
> relatively new to the Zend Framework and OOP too.
>
> I currently use revision 7199 if it's of any relevance.
>
> Now, I've made a view helper to return a Zend_Translate object, see below.
> Then in my view file I call "echo $this->translate()->_('Test');". Now I
> want to generate a source file using poEdit, however, it doesn't seem to
> find any strings. What am I doing wrong?
>
> My view helper:
>
> class Zend_View_Helper_Translate
> {
>    public static $translate;
>
>    public function translate()
>    {
>        if(!isset($this->translate))
>        {
>            $i18nConfig = new Zend_Config_Ini('application/config.ini',
> 'i18n');
>            $this->translate = new Zend_Translate('gettext',
> $i18nConfig->path, 'en');
>        }
>        return $this->translate;
>    }
> }
>
>
> Thanks in advance,
> --
> Vincent
>


Re: How to generate a gettext source file

by Vincent T :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On 21/12/2007, Thomas Weidner <thomas.weidner@...> wrote:
ZF and poEdit are not related together.
They are two completly different products.

You will first have to create a translation source.
How you do this is on you... you can use poEdit or any other program for
this task.

Generally your problem is poEdit and not the framework.
Just set your poEdit to search for the right function.

Normally gettext (for which poEdit was created) uses a function "gettext()"
for translation.
But you are using the abbreviation which you have not said poEdit to search
for.

Solution:
Just set poEdit to search for the method "_" which you are using, and it
will work.

OK, thanks, I wasn't sure whether I had to use "$this->translate()->_" as a keyword or just "_".

It still doesn't work, but since I've also tried just using the gettext() and _() functions it's probably a problem with poEdit.

Thanks anyway.

Greetings
Thomas
I18N Team Leader




--
Vincent

Re: How to generate a gettext source file

by Vincent T :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Well, I've done some digging and just trying many different things, and I've finally been able to successfully generate a source file. I thought I'd share it in case anyone else later has the same problem.

Firstly, I had to configure poEdit to also look for .phtml files (yes, I should've thought of that right away). In File->Preferences, under the parser tab, I edited the list of extensions for PHP to "*.php;*.phtml;".

However, it would still thrown an error every time about not recognizing .phtml and using the C parser or something like that. It did actually recognize my translations, however, only when I put them into double-quoted strings. To make it correctly parse the .phtml files I appended PHP's parser command with " -L php", so it now reads "xgettext --force-po -o %o %C %K %F -L php".

Then I also made a mistake in my catalog settings, since I hadn't set the Base path (under the Paths tab) to the directory where my project was located. For convenience I added the path "application" instead of "." so it wouldn't search through the library et al.

Thanks for the help,

--
Vincent

Re: How to generate a gettext source file

by Oriol Cardona Hernàndez :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Well, I've done some digging and just trying many different things, and
I've finally been able to successfully generate a source file. I thought
I'd share it in case anyone else later has the same problem.

Firstly, I had to configure poEdit to also look for .phtml files (yes, I
should've thought of that right away). In File->Preferences, under the
parser tab, I edited the list of extensions for PHP to
"*.php;*.phtml;".

However, it would still thrown an error every time about not
recognizing .phtml and using the C parser or something like that. It did
actually recognize my translations, however, only when I put them into
double-quoted strings. To make it correctly parse the .phtml files I
appended PHP's parser command with " -L php", so it now reads "xgettext
--force-po -o %o %C %K %F -L php".

Then I also made a mistake in my catalog settings, since I hadn't set
the Base path (under the Paths tab) to the directory where my project
was located. For convenience I added the path "application" instead of
"." so it wouldn't search through the library et al.

Thanks for the help,

--
Vincent

LightInTheBox - Buy quality products at wholesale price