When translating strings in Yii with GetText, do we have to use Yii::t($category,'message')
or gettext's _('message')
syntax?
And then how do we pull the strings into a PO file?
When translating strings in Yii with GetText, do we have to use Yii::t($category,'message')
or gettext's _('message')
syntax?
And then how do we pull the strings into a PO file?
I always use Yii::t('xx','yy') in order to have more control on localization. I can split in more file under
with
This for Yii Framework 1.x
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.
I use it like this:
when i have for example:
in folder
messages
have I folderen
and on this folder I have filelang.php
on this folder
lang.php
I have for example:then when i need call view translate:
and result is:
search
when I change:
Yii::app()->language = de
, I must havemessages/de/lang.php
and on this foler I have:then when i need call view translate:
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-
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