When translating strings in Yii with GetText, do we have to use Yii::t($category,\'message\')
or gettext\'s _(\'message\')
syntax?
And then how
I always use Yii::t('xx','yy') in order to have more control on localization. I can split in more file under
message/LANG/file.php
with
<?php
return array(
'xx' => 'localized',
);
?>
This for Yii Framework 1.x
I use it like this:
when i have for example:
Yii::app()->language = en
in folder messages
have I folder en
and on this folder I have file lang.php
on this folder lang.php
I have for example:
<?php
return array(
'example1'=>'search',
'example2'=>'news',
);
then when i need call view translate:
<?=Yii::t('lang','example1');?>
and result is: search
when I change: Yii::app()->language = de
, I must have messages/de/lang.php
and on this foler I have:
<?php
return array(
'example1'=>'Suche',
'example2'=>'Nachrichten',
);
then when i need call view translate:
<?=Yii::t('lang','example1');?>
result is: Suche
You need to use Yii::t() for translations. with the inbuilt yiic message
command you can generate all the text in to language file.
Example-
Yii::t('app', 'Hello World');
Yii::t('email', 'Welcome');
This will generate 2 files app.php and email.php inside your messages directory. messages/en/app.php & messages/en/email.php
please find more info about Yii translations here
https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n https://www.yiiframework.com/doc/guide/1.1/en/topics.i18n
You can put strings via POEdit app: http://poedit.net/ It allow you to scan your project files and automatically add all required strings into .po file.
If it comes to difference between Yii::t($category,'message') and _('message') - you should use Yii::t($category,'message'). GetText's _('message') works with a quite different po/mo catalog structure.
I personally use POEdit as string scanner and it works like a charm.