I have lots of Yii::t() commands in my application. Now I need to extract them somehow but I don't want to do this manually. How can I extract all those commands easily? Do I have to do it with regular expressions?
I have read the documentation but it doesn't state anything about this.
Yii2 provides already somthing to help you with this topic. You can use the console with two yii commands:
message/config
: With the first command you create a configuration filemessage/extract
: and with the second you extract the Yii:t()
messages based on the configuration fileBy default (part of the configuration file) all messages will be saved into a @app/messages directory that you have to have created before. These files will contain the required php arrays with empty string values for the translations. The files will be named by category that are used in the Yii::t('category', 'message')
commands and are placed into sub directories for the specified language codes.
All is documented in the yii command. Type ./yii help message
into your console. The config file itself also includes documentation.
Hint: don't forget to exclude the vendor directory in the configuration, otherwise the Yii framework messages gets also extracted.
Btw: these commands don't need the i18n configuration that is typically stored in the web.php
or console.php
files. Though, for using the localized messages you have to define it of course.
Some information is now available here in the guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With