Download the PHP package aenzenith/laravel-localizable without Composer

On this page you can find all versions of the php package aenzenith/laravel-localizable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-localizable

Laravel Localizable

This trait offers an efficient and user-friendly solution for localizing model fields within a Laravel application. It grants the ability to set localizable fields without adding new database fields and the capability to translate existing table fields to different languages without adding new fields. This trait streamlines the localization process for your Laravel models by simplifying the management and maintenance of localizable fields.

Installation

To install the package, you can use the following commands:

After installation completed, you have to run these commands to prepare package ready to use:

With publishing, you can access the config file from config/localizable.php

Usage

Setting the locales list

You can modify the locales that will be use, in the config/localizable.php configuration file by adding new languages in the form of language codes and language names to the locales array. For example, if you want to add Spanish and German to the list of available languages, simply you can add the following lines to your configuration file:

Adding the Localizable trait and $localizable property to your model

The fields added to the $localizable array do not need to have a corresponding field in the database table. This allows you to add localizable attributes independently of the database, giving you the flexibility to handle localization without making changes to the underlying table structure.

However, if you wish to localize existing fields in your model, the fields added to the $localizable array will be returned as localized when the model is retrieved, without the need for any changes to the table structure.

Localization process

You can use the getLocalizables method to get the localizable fields of the model for each locale to pass them to the front-end. For example:

The localizables variable will be added to your view data:

You can create a form with the fields you added to the $localizable array and pass the localizables variable to the form. Then you can use the localizables variable to create the localized fields in the form.

Here is an example of a form that uses the localizables variable:

In the Vue.js with Inertia.js:

While utilizing the localizables variable to create localized fields in the form is an option, it is not a requirement. You have the freedom to use your preferred front-end framework to design these fields in a way that aligns with your project's specific needs and requirements. You only need to ensure that you pass the correct parameters to the methods used when saving to the back-end. Below you can find information about the controller methods.

When saving a model in a controller, you can use the following localization methods to handle the localization data:

  1. The localize method allows you to localize a specific field of the model to a specific locale. It accepts three arguments: locale, field and value. For example:

  2. The localizeMany method allows you to localize multiple fields of the model to a specific locale. It accepts two arguments: the locale and an associative array of fields and their values. For example:

  3. The localizeManyLocales method allows you to localize the model to multiple locales. It accepts an array where the keys are the locales and the values are arrays of fields and their values. For example:

If you got the localizables with getLocalizables method and processed in the front-end, you can use the localizeManyLocales method to create the localized values easily. For example:

Retrieving localizations for update

You can get the localized datas with using getLocalizations method after you called the model.

The localizations attribute will be added to your model data:

Then you can process the localized values in front-end and pass the updated values to localizeManyLocales method easily. For example:

Getting localized data

The localized data will be returned automatically according to the application locale. To change the application locale, you can use the setLocale method.

If there is no record for the field you added to $localizable, the field_fallback_value in config/localizable.php will be returned. If you want it to return as null, set the field_fallback option to false.

All of the localized data will stored in localizations table. When a model is deleted, the related localizations will be deleted automatically.

License

MIT

Support

If you have any questions or suggestions, please feel free to contact me. You can also open an issue on GitHub.


All versions of laravel-localizable with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aenzenith/laravel-localizable contains the following files

Loading the files please wait ....