Download the PHP package nalingia/laravel-i18n without Composer
On this page you can find all versions of the php package nalingia/laravel-i18n. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nalingia/laravel-i18n
More information about nalingia/laravel-i18n
Files in nalingia/laravel-i18n
Package laravel-i18n
Short Description An opinionated Laravel package for model internationalisation.
License MIT
Informations about the package laravel-i18n
An opinionated Laravel package for models internationalisation
I18n is an opinionated package to add internationalisation to a Laravel model.
Installation
You can install the package via composer:
Laravel will discover the related service provider.
Usage
This package comes with a ready-to-use migration to enable your model to be internationalised. To create the migration run
and then
It has a minimum configuration available. You can publish using
To enable internationalisation in your models, follow these simple steps:
- Import
Nalingia\I18n\Traits\HasI18n
trait into you model. - Add a public property named
$catalogueAttributes
: it will contains all attributes that will be translated. - Add
'catalogueItems'
to model's$with
array when using Lavavel 5.6 or below. Starting from Laravel 5.7 imported traits can initialize everything needed when a model is booting. HasI18n can append'catalogueItems'
to$with
and$hidden
arrays.
Here's an set up example:
Translations management
There are several way to access property localisations but the easiest one is related to the current application locale:
You can also use this method to access a translation:
Get a catalogue item
Accessing translation for current application locale is as easy as accessing a model attribute:
If you want to access translation for a different locale, you can call translate(string $key, string $locale)
:
or
Retrieve all catalogue items
You can get all available catalogue items for a model by calling getCatalogueItems()
without providing any argument:
Or you can use the accessor
Retrieve all available locales
You can get all available locale for which exist at least one catalogue item by calling getCatalogueLocales()
:
Setting a catalogue item
Setting translation for current application locale is as easy as setting a model's property:
If you want to translate in locales different to the application one you can call setCatalogueItem(string $key, string $locale, $value)
:
Remove a catalotue item
You can delete a translation for a specific field:
Or, you can delete all translation for a locale:
Creating models
You can set catalogue items when creating new model
or you can set only catalogue items that match the current application locale by setting the attribute value without providing any locale key. For example:
is the same as
Change log
Please, see CHANGELOG for more information about what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Testing
You can run the tests with:
or
License
The MIT License (MIT). Please see License File for more information.