homoky's avatar

Translate input names for validation

Hi,

I am doing web app in a different language. I have implemented the lang for validations messages, but how can i change the input names? Is something built right in for this purposes?

For example "user" is in czech "uživatelské jméno".

0 likes
13 replies
usman's avatar

@homoky in the same dir i.e cz create your language file for form and define your translations:

//file: laravel_installation_path/resources/lang/cz/form.php

return [
    'username' => 'uživatelské jméno'
    //more form related translations here.
];
//now you can use this inside your views.
<label for="username">trans('form.username')</label>

I hope it helps.

PS: you will need to set the locale to cz first.

homoky's avatar

Yes. This is possible. But those are strings. Thanks @usman for reply but this is not what I am looking for.

I said that I am looking for translate the validation rules, not the labels.

Let's say that the error is: "The username fields is required".

I translated the the validation messages so it changes to: "username je vyžadované pole."

How to translate "username" globaly? What if there I'll use 10 languages?

bestmomo's avatar

The problem is that input names are in view so if you want to translate you need to :

  • translate input names in view
  • translate input names in rules array of form request.

So you'll get a good localization.

homoky's avatar

There is no better workflow? In L4 there was a possibility to add array of own names to it. Why is there localization when it does not work with another part of the framework? It seems quite incomplete.

michaeldyrynda's avatar

@pmall is on the money. Create a folder in the resources/lang directory called cz, then add your validations.php file in there.

The structure is here.

1 like
homoky's avatar

Thanks @pmall !!! I checked only the validation messages and did not scroll down to check more. You saved my day!

Please or to participate in this conversation.