keevitaja - 1 year 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

keevitaja - 1 year 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 - 1 year ago

And these form posts cannot be edited! Throws 500

The correct html is

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

keevitaja - 1 year ago

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

but not in register.twig

ryanthompson - 1 year 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 - 1 year 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 - 1 year 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 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 - 1 year 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 - 1 year 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 - 1 year ago

Ayayay! That happens lol