Eliovir
(Eliovir)
May 22, 2009, 3:20pm
1
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?
Eliovir
(Eliovir)
May 22, 2009, 11:11pm
2
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.
Eliovir
(Eliovir)
November 11, 2009, 9:46pm
3
As the link is broken, I attach the file again.
guillemc
(Guillemc)
December 1, 2009, 11:23am
4
Thanks, this is very useful. I think that if you add it to the extensions section more people will find it.
Eliovir
(Eliovir)
December 1, 2009, 1:33pm
5
guillemc, thanks for your message.
As you’re the second person who tells it, I’ve added http://www.yiiframework.com/extension/pophpcommand/ , even if it is not an extension, but a simple command.
Eliovir
(Eliovir)
November 10, 2010, 1:23pm
6
Since my last message, I put new version of this command line tool : http://www.yiiframework.com/extension/pophpcommand/ . I hope it could help someone.
bartatamas
(Bartatamas)
February 15, 2011, 12:29pm
7
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’,
);
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
Eliovir
(Eliovir)
February 15, 2011, 3:55pm
8
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.
Eliovir
(Eliovir)
January 4, 2012, 10:32am
9
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
viewfinder
(Stevechen)
February 3, 2012, 6:53am
10
[color="#1C2837 "][size="2"]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[/size][/color]
[color="#1C2837 "][size="2"]The config file was setup as follows:[/size][/color][color="#1C2837 "][size="2"]
<?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? [/size][/color]
motin
(Yiiframework Com)
March 6, 2012, 4:38pm
11
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/motin/emessage-command
My (minor) fixes will be available there. Feel free to fork it in any way you prefer.
Eliovir
(Eliovir)
June 5, 2012, 2:53pm
12
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.
nath-0
(Nathalie Chabert)
October 18, 2012, 12:20pm
13
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 :
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
nath-0
(Nathalie Chabert)
October 18, 2012, 1:50pm
14
nath-0:
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 :
doesn’t work.
I would like to convert my file .php into .po file
thanks
Nath
done77
(Bili Belo)
October 18, 2012, 2:03pm
15
Thanks, this is very useful
Eliovir
(Eliovir)
October 18, 2012, 6:59pm
16
@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 ?)
nath-0
(Nathalie Chabert)
October 19, 2012, 7:36am
17
thanks Elliovir, but it doesn’t work.
With your exemple, the first one, I have this message error :
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 !
nath-0
(Nathalie Chabert)
October 19, 2012, 10:00am
18
here te correct command :
I run this command since C:\Wamp\www\nameOfApplication\protected>
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
Jelmo
(Jelmer)
October 23, 2012, 12:52pm
19
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!
Eliovir
(Eliovir)
October 24, 2012, 5:07pm
20
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',
),
);