how to generate gettext .pot file FROM class constants

Hi everyone!

I have a problem how to handle my gettext translations. I need to generate gettext POT file from constants...

Lets say this is one of my models:

<?php

//user.php

class User extends \Phalcon\Mvc\Model {

     public $name;

     //the problem is how to generete POT file from such strings:
     const E_NAME_DUPLICATE = 'USER.NAME.DUPLICATE'; // Such user name already exists.
     const E_NAME_TOOLONG = 'USER.NAME.TOOLONG'; // User name is too long.

    public function validation() {
        $this->validate(new Phalcon\Mvc\Model\Validator\Uniqueness(array(
            'field'   => 'name',
            'message' => self::E_NAME_DUPLICATE,
        )));
        return !$this->validationHasFailed();
    }
}

Then, somewhare in the view these codes (technically speaking they are validation messages) will be transalted by gettext to user language.

So what I want to achive is to automatically generate the POT file. Base on the above model, the POT file would be sth similiar to:

#. Such user name already exists.
#: user.php:10
msgid "USER.NAME.DUPLICATE"
msgstr ""

#. User name is too long.
#: user.php:11
msgid "USER.NAME.TOOLONG"
msgstr ""

Do you know any tool to do it? For example to add some special comments near to/above such consts and base on this producing a POT file? I have tried to use xgettext but without aby success...

I am looking for any kind of solution (another tool, proper use of xgettext, anything!) how to automate the process. I have lot of such models and messages in my project and I am looking for a good way to handle them.Tkank you!



32.7k

You will probably to develop such a tool.