This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

planetadeleste
planetadeleste

Hello, I want to know if is possible to use replacement parameters in language lines in yaml files. Using something like 'backend::lang.form.create_title' that value is New :name.

thanks

Scott
Scott

For some lines you don't have to, they will be automatically injected. For example, in the config_form.yaml file you can use values like backend::lang.relation.create_name and backend::lang.relation.update_name without needing to specify what :name refers to. So depending on what file you're using these in, it might be worth it to try using the string without specifying the name, you might get lucky.

As for actually using variables in language strings, I don't know of any way to do this directly from the yaml file. I find when I need to do things like this, it's easier to render the string from the controller before displaying whatever you need to display.

Last updated

planetadeleste
Mohsin
Mohsin

Any better solution for this?

In my plugin’s lang.php file I have a string x_label' => 'Some :x label. And in form field I'm using label: acme.plugin::lang.settings.x_label

I want to pass the 'x' in the form field as yaml? I'm looking for something like…

carrot:
    label: acme.plugin::lang.settings.x_label, Carrot

apple:
    label: acme.plugin::lang.settings.x_label, Apple

And in frontend it should appear like Some Carrot label, Some Apple label. The comma doesn’t work so what is the right way to do this?

Last updated

gabsource
gabsource

It's not possible at the moment. The value of the Yaml field is used as the translation key only. It would require to define a specific syntax to parse translation keys with params.

The only solution left for now is to use a hardcoded keys for each label in your example.

carrot:
    label: acme.plugin::lang.settings.x_label_carrot

apple:
    label: acme.plugin::lang.settings.x_label_apple
guillaume.batier2373
guillaume.batier2373

Not very the same issue, but in my fields.yaml file i've to translate a comment like:

comment: <a data-control="popup" data-handler="onLoadContent" href="nojavascript...;" class="btn btn-sm btn-secondary oc-icon-user"> Add Customer </a>

So i've put it directly in the translate file: Lang.php:

'add_customer' => <a data-control="popup" data-handler="onLoadContent" href="nojavascript...;" class="btn btn-sm btn-secondary oc-icon-user"> Add Customer </a>

fields.yaml: comment: prestasafe.erp::lang.customer.add_customer

and it work fine !

Last updated

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.