Trouble with translating in twig views

keevitaja - 5 months ago

Hello!

I do not how to translate some field names in validation errors.

For example i have overridden the register.twig in my theme which contains custom field 'terms'. So users module has a custom field terms!

I have tried to translate this everywhere with no luck.

In register.twig:

<label for="terms"><a href="{{ url('kasutustingimused') }}">{{ trans('labels.read_terms') }}</a></label>

So where can i translate this field for the validation errors?

Answer

- 5 months ago

This is solved with the biggest lol ever. User Module default fields can be translated in published language files. But custom fields just use the label set in the Fields section of the users module admin panel.

keevitaja - 5 months ago

And these form posts cannot be edited! Throws 500

The correct html is

<input type="checkbox" name="terms" id="terms" value="1">

keevitaja - 5 months ago

And in custom views this errors can just be traslated in validation.php with required and attributes

but not in register.twig

ryanthompson - 5 months ago

Instead of overriding the view for translations you really should publish the addon and override the translation files there. Then you won't have to override the "everywhere" just in that spot.

Your second commend has no information for me.. Idk what any of that means can you elaborate?

And on the third comment again I would hesitate to "translate" in the view.

ryanthompson - 5 months ago

Also the title of this discussion is remarkably unclear / unhelpful. If you could change it to something more descriptive that'd be great.

keevitaja - 5 months ago

Hi Ryan!

The second comment about throwing 500? This happens on pyrocms.com forums section when i try to edit my post...

I have published the addon but somehow the validation cannot be translated.

This is what i have in my custom RegisterFormBuilder:

        'terms' => [
            'instructions' => false,
            'rules' => ['required']
        ]

So if user does not check the 'terms' => [ 'instructions' => false, 'rules' => ['required'] ] checkbox, he gets the validation error that terms are required. I am trying to translate the terms field name so it would display in estonian locale "KASUTUSTINGIMUSED" instead of "Terms"

ryanthompson - 5 months ago

Patched this forum module ^_^

Here is where the messages for the validator are translated: https://github.com/anomalylabs/streams-platform/blob/1.2/src/Ui/Form/FormMessages.php

Perhaps that will help you track down what's going on.

keevitaja - 5 months ago

This is solved with the biggest lol ever. User Module default fields can be translated in published language files. But custom fields just use the label set in the Fields section of the users module admin panel.

ryanthompson - 5 months ago

Ayayay! That happens lol