tobias7884
tobias7884

I intent to use message translation with default messages from theme.yaml, but it seems that it is not working like discribed in the plugin documentation.

When all messages are held in the database it is working. But if setting the default values in theme.yaml there is nothing displaying.
For example:
When site name is set like this:

{{ 'Site name'|_ }}

It will be scanned and stored to the database with the code site.name.
With the code from the database column 'code' written in quotations the value is displayed too:

{{ 'site.name'|_ }}

But when I write it to theme.yaml as described in the plugins documentation:

name: My Theme
# [...]

translate:
    en:
        site.name: 'My Website'

and try outputting the value like this:

{{ site.name|_ }}

it generates no output.

Have I something mistaken?

Last updated

mjauvin
mjauvin

This should work, but try deleting the current entry in the Messages page and rescan messages.

tobias7884
tobias7884

Thank you for the reply,

When rescanning the page it takes the text from within the theme.yaml and writes it into the database. But it does not display the text when the key is written without quotation:

{{ site.name|_ }}

When the key is written in quotations:

{{ 'site.name'|_ }}

It works after rescanning and clearing the cache.
What is missed in my opinion is a hint that scanning is required to recognize the value from the theme.yaml, and that the value is fetched from the database. I thought it is working like setting default values this style:

{{ 'Welcome to our website!'|_ }}

But what is not working is changing the value in the theme.yaml. Even after rescanning and clearing the cache in the 'Messages Translation' interface will be displayed the old value.

Is this a lack of documentation, a bug, or am I something missing?

It's not really comfortable to always delete certain values by hand when things are changing. Especially when there are other translations in the table what not allows you to purge it all the time.

Kind regards

mjauvin
mjauvin

When rescanning the page it takes the text from within the theme.yaml and writes it into the database. But it does not display the text when the key is written without quotation:

{{ site.name|_ }}

You always need the quote, this is required for message translation, otherwise twig treats it as a variable, which it is not.

But what is not working is changing the value in the theme.yaml. Even after rescanning and clearing the cache in the 'Messages Translation' interface will be displayed the old value.

Is this a lack of documentation, a bug, or am I something missing?

It's not really comfortable to always delete certain values by hand when things are changing. Especially when there are other translations in the table what not allows you to purge it all the time.

That's the way it works. You are welcome to look at the RainLab.Translate source code to see if you can find a way to change this if you want.

tobias7884
tobias7884

thank you, the quotation thing {{ site.name|_ }} maybe could be updated at the plugins documentation page: https://octobercms.com/plugin/rainlab-translate

If I find the time I'll going to take a look at source code. Maybe I find an appropriate solution to make it more comfortable.

Kindest regards

mjauvin
mjauvin

tobias7884 said:

thank you, the quotation thing {{ site.name|_ }} maybe could be updated at the plugins documentation page: https://octobercms.com/plugin/rainlab-translate

not sure what you mean here.

tobias7884
tobias7884

I mean that in the documentation unter the 'Message translation' section it says :

{{ site.name|_ }}

{{ 'Welcome to our website!'|_ }}

{{ 'Hello :name!'|_({ name: 'Friend' }) }}

Should it not be:

{{ 'site.name'|_ }}

{{ 'Welcome to our website!'|_ }}

{{ 'Hello :name!'|_({ name: 'Friend' }) }}

Last updated

mjauvin
mjauvin

If site is an array like below, that would work too:

{% set site = {name: 'my name', address: 'my address'} %}

{ site.name | _} 
tobias7884
tobias7884

Ah, Okay! Thank you!

1-9 of 9