Localization

  1. Change config file
  2. Publish locale files
  3. Publish locale layout files
  4. Generate your CRUD
  5. Support new Locales

Change Config File

To get started with localization you must need to change option localized to true.

Publish Locale Files

Next, publish locale files before generating CRUD. Publish locale files by running following command.


php artisan infyom:publish --localized 

Above command will publish the following locale files into resources\lang\en\ directory

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

  • resources
    • lang
      • en
        • auth.php
        • crud.php
        • messages.php
  • auth.php
    • This file contain language lines for login, registration, forgot-password, reset-password, emails and etc..

  • crud.php
    • This file contain 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 locale layout files

If you have already published layout without localization option, then To get it worked with localization, you need to overwrite your normal files with localized files, for that you need to run the following command.


php artisan infyom.publish:layout --localized 

This command will overwrite app, sidebar, login, register, menu and other blade files with localized files.

Generate Your CRUD

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


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.

  • resources
    • 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 lang 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 resources\lang\. and copy all files from resources\lang\en\ directory and paste into es directory.
  • Copy all files from resources\lang\en\ directory to es directory.
  • Change all English values of all the keys to Spanish values.
Made with Generator Hire Us