yiisoft / yii2-twig

Yii 2 Twig extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
137 stars 62 forks source link

twig and i18n #116

Closed rauwebieten closed 4 years ago

rauwebieten commented 4 years ago

How can I translate messages in twig templates? It seems there is not function/filter defined.

I can use {{ app.i18n.translate('app','First name',{},'nl-BE') }} But is there a shortcut like Yii::t ?

Also, can the cli-command for extracting messages find these messages?

samdark commented 4 years ago

Cli command can not find these. Likely it could be adjusted for it but I haven't looked into it. Also there's no shortcut for t().

rauwebieten commented 4 years ago

A shortcut is easily added in the twig config:

...
'functions' => [
    't' => [\Yii::class,'t']
]
...

Also, when my twig templates are compiled into the cache directories, the extractor can find them now by parsing the compiled .php files.

samdark commented 4 years ago

Oh, cool. t() could be implemented by default and pointing extraction to compiled templates could be documented.

developedsoftware commented 2 years ago

Sorry to comment on a closed issue, but this does not appear to be picked up by

console/controllers/MessageController.php

Can Yii.t or t( calls in twig files be "extracted" like Yii::t in PHP files?