exolnet / laravel-translation
Library to manage Laravel translations
Installs: 10 207
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 5
Forks: 0
Open Issues: 5
Requires
- php: ^8.1
- astrotomic/laravel-translatable: ^11.0
- illuminate/contracts: ^10.0|^11.0
- illuminate/routing: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- illuminate/translation: ^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.2
- mockery/mockery: ^1.4
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.6
Suggests
- exolnet/laravel-translation-editor: Allows translation edition through the browser
This package is auto-updated.
Last update: 2024-10-23 20:06:19 UTC
README
Library to manage Laravel translations
Installation
Require this package with composer:
composer require exolnet/laravel-translation
To make sure the routing system is using the one supporting the translation you must edit your bootstrap/app.php
to change the Application class import
sed -i '' 's/Illuminate\\Foundation\\Application/Exolnet\\Translation\\Application/g' bootstrap/app.php
Now you're ready to start using the translation in your application.
Config
Config Files
In order to edit the default configuration (where for e.g. you can find available_locales
) for this package you may execute:
php artisan vendor:publish --provider="Exolnet\Translation\TranslationServiceProvider"
After that, config/translation.php
will be created. Inside this file you will find all the fields that can be edited in this package.
Usage
Exolnet Translation uses the URL given for the request. In order to achieve this purpose, a route group should be added into the routes/web.php
file. It will filter all pages that must be localized.
// routes/web.php Route::groupLocales(function () { Route::get('/', ['as' => 'home', 'uses' => 'HomeController@index']); });
Once this route group is added to the routes file, a user can access all locales added into available_locales
. For example, a user can now access two different locales, using the following addresses:
http://url-to-laravel/en
http://url-to-laravel/fr
If you when to remove the locale prefix on the base locale you need to set the $avoidPrefixOnBaseLocale
to true
when defining the groupLocale
// routes/web.php Route::groupLocales(function () { Route::get('/', ['as' => 'home', 'uses' => 'HomeController@index']); })->hiddenBaseLocale();
Testing
To run the phpUnit tests, please use:
composer test
Contributing
Please see CONTRIBUTING and CODE OF CONDUCT for details.
Security
If you discover any security related issues, please email security@exolnet.com instead of using the issue tracker.
Credits
License
This code is licensed under the MIT license. Please see the license file for more information.