Download the PHP package ozanakman/laravel-multilingual without Composer
On this page you can find all versions of the php package ozanakman/laravel-multilingual. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ozanakman/laravel-multilingual
More information about ozanakman/laravel-multilingual
Files in ozanakman/laravel-multilingual
Package laravel-multilingual
Short Description Simple localization for Laravel apps.
License MIT
Informations about the package laravel-multilingual
Multilingual Laravel :globe_with_meridians:
Introduction
Multilingual is a localization package for Laravel apps. It has built-in methods to make localization simple. It aims to give you developing speed and not to worry about locales.
This package created by Ozan Akman
- Handling redirects easily (domain or path based)
- Extended router class for localized routes
- Blade directive @forEachLocale
- Highly customizable
Installation
You may use Composer to install Multilingual into your Laravel project:
Note: Multilingual requires Laravel 5.7.0+.
After installing Multilingual, publish its assets using the multilingual:install
Artisan command. It will migrate locales
and translations
tables.
After publishing Multilingual's assets, its primary configuration file will be located at config/multilingual.php
.
Configuration
There are two options in the config file.
pattern
is used to handle redirects and how should system treat to urls. Pattern can only be domain
or path
.
when you select domain
as the pattern. Localized url would be something like this:
en.domain.com
or tr.domain.com
.
when you select path
as the pattern. Localized url would be something like this:
domain.com/en
or domain.com/tr
.
The other option is just for customizing middleware. You can either use OzanAkman\Multilingual\Middleware\Localize
which is handling redirects or create your own.
Content of the published config file
Localized Routes
There is a mixing for localized routes that you can use. Route::locale
creates localized urls for each locale. In the example below, User will see welcome
view by visiting domain.com/en/home
or domain.com/tr/home
You may also add attributes to Route::locale
as same as Route::group
method
After all, it's just a shortcut.
Blade Directive
You can easily handle locale based components like locale selection dropdown or multilingual content editor, etc..
You can use this directive as much as you want. Locales are cached behind scenes. So, no need to worry.
Models
Locale
and Translation
model files available under OzanAkman\Multilingual\Models
namespace.
Locales
-
You can add a new locale by calling
Artisan
command: - Removing a language
Be careful, this command will delete all translations that belongs to the locale.
Manually, you can use Locale model to add/edit/remove a locale.
Translations
Add OzanAkman\Multilingual\Models\Traits\HasMultilingualContent
trait to your model files.
-
Getting translated version of the model:
-
Translating model to other locales:
-
Removing translation:
- Handling translation slugs is so easy. You just need to add
slugSource()
method to your main model.
And now when you add a translation Multilingual will generate slug
from title
column by cocur/slugify
package.
Testing
Multilingual uses Orchestra\Testbench
to run tests.
Contributing
Please see CONTRIBUTING for details.