I want to translate the login view into Spanish, with the messages E-mail address
, Password
, Remember me
, etc. According to the documentation, inside resources/lang/
I have to create a file called es.json
. This works fine. However, there is a problem. As you create views, this file will grow, and it can get really long. What I want is to see how I can divide the texts into a translation file for each view. I have tried everything that the documentation puts, and what I have found on the Internet (which is more of the same), and it does not work for me. The moment I put phrases into other files that aren't called es.json
, there's no way to access them.
As far as I know, Laravel doesn't have any option to load only certain files for a certain language. That is, once the language is detected, it loads all the files of that language (or otherwise, of that folder). So if your question is related to getting better performance, I think there is no solution at the moment.
Now, if your question is focused on "how to divide" a certain file into several to have everything more organized, it's simple: you just have to name your files in a certain way: users, products, etc. and when generating the translation, pass the label preceded by the file in question as a parameter, where it is the same. Namely:
In the "users" file:
And to get the translation in your view/controller...