October: Can't call "trans()" function on the views (Twig)

Created on 17 Dec 2016  路  4Comments  路  Source: octobercms/october

Expected behavior

I've decided to make texts _inside views_ translatable with plugin lang files. So, when I use
{{ trans("acme.demo::lang.string.example") }}, I'm expecting translated string value on the actual view.

Actual behavior

But I encounter with "Unknown trans() function." exception instead. Testing "trans()" inside _Models_ or _Components_ is working without any issues.

October build

My current October build is: 382.

Most helpful comment

|trans is a filter in the system

{{ "acme.demo::lang.string.example"|trans }}

All 4 comments

trans is only available in PHP. Check out the underscore twig filter from the translate plugin. There are different ways to provide translations. Maybe read up on it first https://octobercms.com/plugin/rainlab-translate

As a side note, while you can add a reference to Lang::get() (which is effectively the implementation of trans() as a twig function / filter to accomplish what you desire, there is one issue with doing it that way. It's going to use your backend language settings on a frontend view; that's not going to have your intended results.

Like @jBOKA said, look into frontend translation via RainLab.Translate.

Thank you so much! It's more clear for me now :)
I'll try the twig filter of RainLab.Translate as fast as possible.

|trans is a filter in the system

{{ "acme.demo::lang.string.example"|trans }}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mittultechnobrave picture mittultechnobrave  路  3Comments

m49n picture m49n  路  3Comments

ChVuagniaux picture ChVuagniaux  路  3Comments

mittultechnobrave picture mittultechnobrave  路  3Comments

jvanremoortere picture jvanremoortere  路  3Comments