Skip to content

Localization

Change Config File

To get started with localization you must need to change option

sh
'options' => [
    'localized' => true,
],

Publish Locale Files

Next, If you haven't publish locale files before generating CRUD. Publish locale files by running following command.

If you have any custom locales added to lang/en/auth.php then it will be overwritten. so take a backup if need.

sh
php artisan infyom:publish --localized

Above command will publish locale files into resources\lang\ directory for various available languages.

NOTE: Default locale files will be published for english language.

  |- lang
      |- en
          |- auth.php
          |- crud.php
          |- message.php
  • auth.php
    • This file contains language lines for login, registration, forgot-password, reset-password, emails etc..
  • crud.php
    • This file contains language lines for CRUD buttons like create, update, cancel, save, etc., and confirmation text.
  • message.php
    • This file will contain CRUD operation messages text like success, model not found, retrieved, deleted and updated.

Publish Layout Files

While using laravel-ui-adminlte, if you want to publish your layout files with localization support, run the following command,

sh
php artisan ui adminlte-localized --auth

Generate Your CRUD

After completing the above changes, now we are ready to generate CRUD with localization by running the following command.

sh
php artisan infyom:scaffold Post

Note: Where Post is ModelName

If localization is enabled then this command will generate new locale files into resources\en\models\ directory. File name will be plural of model name, e.g if model name is Post then it will generate posts.php.

  |- lang
      |- en
          |- models
              |- posts.php

This file will contain Singular Model Name, Plural Model Name and Model Fields.

Support for new Locales

As mentioned above, Generator will only generate locale files for english for model names and fields. Now to support a new locales, you need to create those locale files manually in relevant language folder with same keys but with different values.

For e.g., If you want to support Spanish locale, then perform the following steps.

  • Create new directory with name es into lang\, and copy all files from lang\en\ directory and paste into es directory.
  • Change all English values of all the keys to Spanish values, including,
    • singular
    • plural
    • fields