James
James

Reputation: 176

Laravel localization files with database

I want to make multilanguage site with laravel with [en:es] language. I created en and es folders in lang folder. Then i created translate.php file in those folder. File looks like.

<?php

return [
    'identificator' => 'text',
];

How to import all identificators and text to database table for CRUD and export'em back to translate.php file?

Upvotes: 1

Views: 5001

Answers (1)

James
James

Reputation: 176

The solution is here in Github

The content in the languages table is:

| id | locale | name    |
-------------------------
| 1  | en     | english |
| 2  | es     | spanish |

The relevant content in the language_entries table is:

| id | locale | namespace | group       | item            | text                    |
-------------------------------------------------------------------------------------
| 1  | en     | *         | validations | missing.name    | Name is missing         |
| 2  | en     | *         | validations | missing.surname | Surname is missing      |
| 3  | en     | *         | validations | min_number      | Number is too small     |
| 4  | es     | *         | validations | missing.name    | Falta nombre            |
| 5  | es     | *         | validations | missing.surname | Falta apellido          |

Output for different keys with es locale:

    trans('validations.missing.name');   //    'Falta nombre'
    trans('validations.min_number');     //    'Number is too small'
    trans('validations.missing.email');  //    'missing_email'

Upvotes: 1

Related Questions