All Projects โ†’ akalongman โ†’ Laravel Multilang

akalongman / Laravel Multilang

Licence: other
Package to integrate multi language (multi locale) functionality in Laravel 5.x.

Projects that are alternatives of or similar to Laravel Multilang

Laravel Js Localization
๐ŸŒ Convert your Laravel messages and consume them in the front-end!
Stars: โœญ 451 (+859.57%)
Mutual labels:  laravel, laravel-package, localization
Laravel Multilingual Routes
A package to handle multilingual routes in your Laravel application.
Stars: โœญ 241 (+412.77%)
Mutual labels:  laravel, laravel-package, localization
Blade Migrations Laravel
An intelligent alternative version of Laravel 5/6 Database Migrations - uses raw-sql syntax, transactions, auto-rollback, UP-DOWN-UP testing
Stars: โœญ 25 (-46.81%)
Mutual labels:  laravel, laravel-package
Laravel Mailguneu
Allow customising the Mailgun server URL to use EU servers.
Stars: โœญ 13 (-72.34%)
Mutual labels:  laravel, laravel-package
Laravel Translatable
It's a Laravel database translations manager
Stars: โœญ 47 (+0%)
Mutual labels:  laravel, laravel-package
History Tracker
Laravel Model history tracking made easy
Stars: โœญ 46 (-2.13%)
Mutual labels:  laravel, laravel-package
Eloquent Ldap
A Laravel 5.1 package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.
Stars: โœญ 19 (-59.57%)
Mutual labels:  laravel, laravel-package
Doorman
Limit access to your Laravel applications by using invite codes
Stars: โœญ 913 (+1842.55%)
Mutual labels:  laravel, laravel-package
Laravel Blade Directives
A collection of nice Laravel Blade directives
Stars: โœญ 813 (+1629.79%)
Mutual labels:  laravel, laravel-package
Cms
Statamic 3: The Core Composer Package
Stars: โœญ 965 (+1953.19%)
Mutual labels:  laravel, laravel-package
Laravel Database Logger
Log database query sql in Laravel Application, support Guard,Auth to multiple file record
Stars: โœญ 31 (-34.04%)
Mutual labels:  laravel, laravel-package
Laravel Settings
Simple Settings package for a laravel application
Stars: โœญ 45 (-4.26%)
Mutual labels:  laravel, laravel-package
Simple Cache
An easy to use Caching trait for Laravel's Eloquent Models.
Stars: โœญ 19 (-59.57%)
Mutual labels:  laravel, laravel-package
Laravel Log
Simple API to write logs for Laravel.
Stars: โœญ 19 (-59.57%)
Mutual labels:  laravel, laravel-package
Laravel Aws Sns
Laravel package for the AWS SNS Events
Stars: โœญ 24 (-48.94%)
Mutual labels:  laravel, laravel-package
Package Skeleton
๐Ÿ“ฆ My base for PHP packages.
Stars: โœญ 6 (-87.23%)
Mutual labels:  laravel, laravel-package
Chatify
A Laravel package that allows you to add a complete user messaging system into your new/existing Laravel application.
Stars: โœญ 885 (+1782.98%)
Mutual labels:  laravel, laravel-package
Laravel Qrcode Ecommerce
This is a complete laravel project that handles qrcodes, payments, api/microservices, and ecommerce
Stars: โœญ 36 (-23.4%)
Mutual labels:  laravel, laravel-package
Twitter
Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x
Stars: โœญ 755 (+1506.38%)
Mutual labels:  laravel, laravel-package
Laravel Notify
Flexible Flash notifications for Laravel
Stars: โœญ 787 (+1574.47%)
Mutual labels:  laravel, laravel-package

Laravel 5.x MultiLanguage

Build Status Code Coverage Code Quality Latest Stable Version Total Downloads Downloads Month License

This is a very useful package to integrate multi language (multi locale) functionality in Laravel 5.x. It includes a ServiceProvider to register the multilang and Middleware for automatic modification routes like http://site.com/en/your-routes.

This package uses database for storing translations (it caches data on production environment for improving performance) Also package automatically adds in database missing keys (on the local environment only).

Table of Contents

Installation

Install this package through Composer.

Edit your project's composer.json file to require longman/laravel-multilang

Create composer.json file:

{
    "name": "yourproject/yourproject",
    "type": "project",
    "require": {
        "longman/laravel-multilang": "~1.2"
    }
}

And run composer update

Or run a command in your command line:

composer require longman/laravel-multilang

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:

Longman\LaravelMultiLang\MultiLangServiceProvider::class,

Also you can add facade to the alias array in the config/app.php

'MultiLang' => Longman\LaravelMultiLang\Facades\MultiLang::class,

Copy the package config to your local config with the publish command:

php artisan vendor:publish --provider="Longman\LaravelMultiLang\MultiLangServiceProvider"

After run multilang migration command

php artisan multilang:migration

Its creates multilang migration file in your database/migrations folder. After you can run

php artisan migrate

Also if you want automatically change locale depending on url (like http://site.com/en/your-routes) you must add middleware in app/Http/Kernel.php

I suggest add multilang after CheckForMaintenanceMode middleware

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \Longman\LaravelMultiLang\Middleware\MultiLang::class,
];

In your RoutesServiceProvider modify that:

MultiLang::routeGroup(function($router) {
    require app_path('Http/routes.php');
});

or directly in app/Http/routes.php file add multilang group:

MultiLang::routeGroup(function($router) {
    // your routes and route groups here
});

Or if you want only translate strings without automatic resolving locale and redirect, you can manually set locale in your application like:

App::setLocale('en');

Usage

Translating

Everywhere in application you can use t() helper function like:

$string = t('Your translatable string');

You can use markers for dynamic texts and pass any data like

$string = t('The :attribute must be a date after :date.', ['attribute' => 'Start Date', 'date' => '7 April 1986']);

which will be return The Start Date must be a date after 7 April 1986.

Blade Templates

In blade templates you can use just @t() notation like

@t('Your translatable string')

which is equivalent to {{ t('Your translatable string') }}

URL Generation

Also you can use lang_url() helper function for appending current lang marker in urls automatically.

$url = lang_url('users'); // which returns /en/users depending on your language (locale)

You can force locale and get localized url for current url for example.

$url = lang_url('users', [], null, 'ka'); // which returns /ka/users ignoring current locale

or

$url = lang_url('en/users', [], null, 'ka'); // also returns /ka/users

Also you use named routes via lang_route() function

$url = lang_route('users'); // which returns en.users depending on your language (locale)

Also Request::locale() always will return current locale.

Note: Texts will be selected after firing Laravel's LocaleUpdated event. Therefore you should use MultiLang middleware, or manually set locale in the application.

Text Scopes

If you want group translations by some scope, in package available defining of scopes. For example to define scope admin in application, you should call:

app('multilang')->setScope('admin');

before setting the locale.

Note: Default scope is global

Import/Export Texts

For versioning texts with source code (git/svn) and easy management, there is possible import texts from yml file and also export in the file.

yml file format is:

-
  key: 'authorization'
  texts:
    en: 'Authorization'
    ge: 'แƒแƒ•แƒขแƒแƒ แƒ˜แƒ–แƒแƒชแƒ˜แƒ'
-
  key: 'registration'
  texts:
    en: 'Registration'
    ge: 'แƒ แƒ”แƒ’แƒ˜แƒกแƒขแƒ แƒแƒชแƒ˜แƒ'

Run commands for possible options and more information:

php artisan help multilang:import

php artisan help multilang:export

TODO

write more tests

Troubleshooting

If you like living on the edge, please report any bugs you find on the laravel-multilang issues page.

Contributing

Pull requests are welcome. See CONTRIBUTING.md for information.

License

Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under.

Credits

Full credit list in CREDITS

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].