Download the PHP package themsaid/laravel-multilingual without Composer

On this page you can find all versions of the php package themsaid/laravel-multilingual. 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-multilingual

Laravel 5 Multilingual Models

Latest Version on Packagist Total Downloads

This laravel package makes Eloquent Models attributes translatable without the need to separate database tables for translation values.

You simply call $country->name and you get a value based on your application's current locale.

You can also call $country->nameTranslations->en to get the value of a specific locale.

You can check all the translations of a given attributes as easy as $country->nameTranslations->toArray().

Installation

Begin by installing the package through Composer. Run the following command in your terminal:

Once composer is done, add the package service provider in the providers array in config/app.php

Finally publish the config file:

That's all, you are now good to go.

Usage

First you need to make sure that the translatable attributes has a mysql field type of text or json, if you are building the database from a migration file you may do this:

Now that you have the database ready to save a JSON string, you need to prepare your models:

Now our model has the name attribute translatable, so on creating a new Model you may specify the name field as follow:

It'll be automatically converted to a JSON string and saved in the name field of the database, you can later retrieve the name like this:

This will return the country name based on the current locale, if the current locale doesn't have a value then the fallback_locale defined in the config file will be used.

In case nothing can be found an empty string will be returned.

You may also want to return the value for a specific locale, you can do that using the following syntax:

This will return the English name of the country.

To return an array of all the available translations you may use:

Validation

You can use the new array validation features released with laravel 5.2 to validate the presence of specific locales:

However a validation rule is included in this package that deals with requiring all the validations to be provided:

The translatable_required rule will make sure all the values of the available locales are set.

You may define the available locales as well as the fallback_locale from the package config file.

Now you only need to add the translated message of our new validation rule, add this to the validation.php translation file:

Queries

If you're using MySQL 5.7 or above, it's recommended that you use the json data type for housing translations in the Database, this will allow you to query these columns like this:

However in laravel 5.2.23 and above you can use the fluent syntax:


All versions of laravel-multilingual with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ~5.1
php Version >=5.3.0
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 themsaid/laravel-multilingual contains the following files

Loading the files please wait ....