Yii Framework Forum: message translation into .po - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

message translation into .po Rate Topic: -----

#1 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 22 May 2009 - 10:20 AM

I'm trying the translation functionnality, which is a core problem for me.

I used it like this:
for($i=0; $i < 5; $i++) {
        echo Yii::t('yii', '0#There is not any file|1# There is one file |1,Inf#There are {number} files', array($i, '{number}'=>$i)) . '<br/>';
}


and I got

Quote

Il n'y a pas de fichier

Il y a un fichier

Il y a 2 fichiers

Il y a 3 fichiers

Il y a 4 fichiers


No problem. An example in the documentation or in the cookbook could be good.

I can grab the sentence into the message php files with
protected/yiic message protected/messages/config.php


How can I grab into gettext .po file, which is much easier to translate?
0

#2 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 22 May 2009 - 06:11 PM

As PHPMessageSource is said faster and as I did not find any response, I played with the command line and made a converter between po and php.

- Copy the attachment to
protected/commands/PoPHPCommand.php


- Convert .php to .po
protected/yiic pophp php protected/messages/config.php
(beware of the header and specially the nplural formula)

- Convert .po to .php
protected/yiic pophp php protected/messages/config.php


The code is widely inspired from CGettextPoFile.php and cli/commands/MessageCommand.php.

Attached File(s)


0

#3 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 11 November 2009 - 04:46 PM

As the link is broken, I attach the file again.

Attached File(s)


0

#4 User is offline   guillemc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 14-October 09

Posted 01 December 2009 - 06:23 AM

Thanks, this is very useful. I think that if you add it to the extensions section more people will find it.
0

#5 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 01 December 2009 - 08:33 AM

guillemc, thanks for your message.

As you're the second person who tells it, I've added http://www.yiiframew...n/pophpcommand/ , even if it is not an extension, but a simple command.
0

#6 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 10 November 2010 - 08:23 AM

Since my last message, I put new version of this command line tool : http://www.yiiframew...n/pophpcommand/ . I hope it could help someone.
0

#7 User is offline   b_t 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 15-February 11

Posted 15 February 2011 - 07:29 AM

Hi!

I've just downloaded the EMessageCommand.zip extension for yii and I can't get it work.

- I put a "echo Yii::t('loc', 'HELLO');" line in my php
- I called "protected/yiic message protected/messages/config.php" to generate php files.
This call generated the following file in name loc.php (comments are removed):

<?php
return array (
'HELLO' => 'Hello',
);

- I executed your command to generate po files: "protected/yiic emessage php protected/messages/config.php"
This call generated the loc.po file:

msgid ""
msgstr ""
"Project-Id-Version: loc.php\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-02-15 12:54+0000\n"
"PO-Revision-Date: 2011-02-15 12:54+0000\n"
"Last-Translator: \n"
"Language-Team: en <translation-team-en@lists.sourceforge.net>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Yii EMessage\n"
"Generated-By: Yii EMessage\n"
"Plural-Forms: nplurals = 2; plural = n ! = 1;\n"

msgid "HELLO"
msgstr "Hello"

- When I execute the original php: "echo Yii::t('loc', 'HELLO');"
Yii/CGettextPoFile.php can read this file, loads messages, but
returns an empty array because the context of the call ('loc') doesn't
equal the context of the message ('').

There is no msgctxt in the file.

Can you help me? Where is the problem about these context values?
Yii assumes that the context is in the "msgctxt" line and your command
doesn't generated such lines.

Thank you,
Tamás
0

#8 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 15 February 2011 - 10:55 AM

View Postb_t, on 15 February 2011 - 07:29 AM, said:

Can you help me? Where is the problem about these context values?
Yii assumes that the context is in the "msgctxt" line and your command
doesn't generated such lines.


Hi,

yes, you're right, the generator does not write the "msgctxt" line.

In fact, I created this script to use a translation tool like Lokalize and to update my .po files to Launchpad so as to benefit collaborative translation.

the .po files need more resource to be read, I prefer convert the .po files to .php files after, and use the standard way of Yii.

the context is not handled, but it could be done easily in savePo(), with the basename of the file.
0

#9 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 04 January 2012 - 05:32 AM

The last release do not need any more the config file path.

It is possible to find duplicates without considering the case:

protected/yiic emessage duplicates --caseSensitive=false


EMessageCommand
0

#10 User is offline   View Finder 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 11-December 11

Posted 03 February 2012 - 01:53 AM

When I run "protected/yiic emessage php" command, I get the error saying:
PHP Error[8]: Undefined variable: sourcePath
in file …/protected/commands/EMessageCommand.php at line 210


The config file was setup as follows:
<?php

return array(
	'sourcePath'=>'../WebRoot/themes/deepBlue/views/',
	'messagePath'=>'../protected/messages/',
	'languages'=>array('en', 'tw', 'jp'),
);


What gives? If I remove the sourcePath in the config, it then tells me I need that variable defined (Error: The configuration file must specify "sourcePath", "messagePath" and "languages".)
I setup the directory structure so that framework, WebRoot, runtime, protected folders are under the same root directory.
Can anyone help?

0

#11 User is offline   Motin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 17-May 10

Posted 06 March 2012 - 11:38 AM

I found no easy way to contribute to changes so I set up a git mirror and fork of the extension on https://github.com/m...message-command

My (minor) fixes will be available there. Feel free to fork it in any way you prefer.
0

#12 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 05 June 2012 - 09:53 AM

I was not aware of your replies. I've just seen them. I subscribed again to the topic.

Thanks Motin for your corrections.

I've updated the extension EMessageCommand. It contains new actions :
check
,
credits
and
removeEmptyFiles
.

I did not forked your branch on GitHub, because I use theses files in a project.
0

#13 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 18 October 2012 - 07:20 AM

hello,

I've just downloaded the EMessageCommand.zip extension for yii and I can't get it work.

Someone can give me a exemple of the config.php ?

I put this file in this directory :

\application\protected\messages\

I use this cmd :

c:\wamp\bin\php\php5.4.3\php.exe yiic message messages/config.php

I have this message error in my console :

Quote

Error : the configuration file must specify "sourcePath","messagePath" and "language"


and here my config.php :

return array(
	'sourceePath'=> dirname(__FILE__).DIRECTORY_SEPARATOR.'../protected/',
    'messagePath'=> dirname(__FILE__).DIRECTORY_SEPARATOR.'../protected/messages/',
    'languages' => array('en','fr'),
    'launchpad' => true,
    'fileTypes' => array('php','po'),
    'translator'=>'Yii::t',
    
    )


any advice or ideas?

Thanks

Nath
0

#14 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 18 October 2012 - 08:50 AM

View Postnath-0, on 18 October 2012 - 07:20 AM, said:

hello,

I've just downloaded the EMessageCommand.zip extension for yii and I can't get it work.

Someone can give me a exemple of the config.php ?

I put this file in this directory :

\application\protected\messages\

I use this cmd :

c:\wamp\bin\php\php5.4.3\php.exe yicc message messages/config.php

I have this message error in my console :



and here my config.php :

return array(
	'sourceePath'=> dirname(__FILE__).DIRECTORY_SEPARATOR.'../protected/',
    'messagePath'=> dirname(__FILE__).DIRECTORY_SEPARATOR.'../protected/messages/',
    'languages' => array('en','fr'),
    'launchpad' => true,
    'fileTypes' => array('php','po'),
    'translator'=>'Yii::t',
    
    )


any advice or ideas?

Thanks

Nath


Here the correct config.php

return array(
        'sourcePath'=>'../protected/views/',
        'messagePath'=>'../protected/messages/',
        'languages'=>array('en', 'fr'),
);




now my problem is that the command :

Quote

c:\wamp\bin\php\php5.4.3\php.exe yiic php messages/config.php


doesn't work.
I would like to convert my file .php into .po file

thanks

Nath
0

#15 User is offline   done77 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-October 12

Posted 18 October 2012 - 09:03 AM

Thanks, this is very useful
0

#16 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 18 October 2012 - 01:59 PM

@nat-0, try with

c:\wamp\bin\php\php5.4.3\php.exe yiic emessage php messages/config.php


from protected.

or
protected/yiic.bat emessage php protected/messages/config.php


(I do not use windows,`protected/yiic.bat` exists, isn't it ?)
0

#17 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 19 October 2012 - 02:36 AM

thanks Elliovir, but it doesn't work.
With your exemple, the first one, I have this message error :

Quote

The configuration file protected/message/config.php does not exist


even if I put protected/message/config.php protected/message/config.php of message/config.php

If I try

c:\wamp\bin\php\php5.4.3\php.exe yiic emessage php messages/config.php


he do nothing and show me the commands available (emessage,message,migrate,shell,webapp.

And with your last exemple, eh told me that he doesn't know yicc,bat as a internal commad !
0

#18 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 19 October 2012 - 05:00 AM

here te correct command :

I run this command since C:\Wamp\www\nameOfApplication\protected>

Quote

c:\wamp\bin\php\php5.4.3\php.exe yiic EMessage php --config=messages/config.php


to convert php file into po file.

Here where I put the file downloaded :

\protected\extensions\emessage-command\commands\EMessageCommand.php
protected\extensions\emessage-command\helpers\CLI.php

in the file console.php I Add this code

  
    'import' => array(
		'application.extensions.emessage-command.components.helpers.CLI',
	),
	'commandMap' => array(
		'emessage' => array(
			'class' => 'application.extensions.emessage-command.commands.EMessageCommand',
		),
	),


protected\messages\config.php

<?php

return array(
        'sourcePath'=>'../protected/',
        'messagePath'=>'../protected/messages/',
        'languages'=>array('en', 'fr'),
        'launchpad' => true,
);


thank you Elvior for your code
0

#19 User is offline   Jelmo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 23-October 12

Posted 23 October 2012 - 07:52 AM

I can't seem to get this to work for the live of me.
I've downloaded the EmessageCommand package, and included.
I've created an config file under protected/messages called emssagesConfig.php which has the following variables
return array(
        'sourcePath' => '../protected/views/',
        'messagePath' => '../protected/messages/',
        'languages' => array('en_us', 'nl_nl'),
		'launchpad' => false,
		'fileTypes' => array('php'),
		'exclude' => array('.svn', 'messages', 'config.php'),
		'translator' => 'Yii::t'
);


Removing any of these vars will cause an error when running the command

When i run the command yiic emessage php --config=messages/emessagesConfig.php i get the following error:
PHP Error[2]: strlen() expects parameter 1 to be string, array given
    in file EMessageCommand.php at line 564


I've looked up the line, and added some code that will check if the value given to strlen() is an array, and if so, will print it. The output of that is the following
array(2) {
  [0]=>
  string(5) "en_us"
  [1]=>
  string(5) "nl_nl"
}


So it seems to me EmessagesCommand is trying to read my config file into a po file? I can't seem to find out what is wrong here. Any help is greatly appreciated!
0

#20 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 24 October 2012 - 12:07 PM

I use this configuration, with absolute paths:
return array(
        'sourcePath'=>dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..',
        'messagePath'=>dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'messages',
        'languages'=>array('da', 'de', 'eo', 'fr', 'it', 'nl', 'pl'),
        'autoMerge'=>true,
        'launchpad'=>true,
        'skipUnused'=>true,
        'fileTypes'=>array('php'),
        'exclude'=>array(
                '.svn',
                '.bzr',
                '/messages',
                '/protected/vendors',
        ),
);

0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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