menarasolutions / fluent-laravel
Laravel package for Fluent translations (application localisation)
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ^6.2
- laravel/framework: 5.4.*|5.3.*
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: 3.7.*
This package is auto-updated.
Last update: 2024-11-29 05:44:18 UTC
README
Laravel package for Fluent translations (application localisation)
Localization flow of Laravel
Laravel offers two options for localization: key-based texts and plain JSON texts.
Key-based language files: {locale}/{group}.php (PHP array format)
Use: __('auth.please_wait')
Drawbacks: after adding a new key to the main locale, the same key has to be manually added to all other locales.
It's easy for locales to go out of sync. Some texts may be present in the language files but not be in use anywhere.
JSON files: {locale}.json (JSON format)
Use: __('Please wait, authorizing')
Drawbacks: if the same text needs different translations in different contexts, this doesn't work well.
It's hard to say how much of content is translated because there is no original text dictionary.
Localization flow of Fluent
Fluent offers you to store and manage your translations in the "cloud" which makes it trivial to outsource translations to translation market places or colleagues. Even if you translate everything yourself, Fluent interface will be far more convenient for this task (eg. you will see clearly current status, get hints from MTs, find unused texts, etc).
Installation
Use Composer to install this package:
$ composer require menarasolutions/fluent-laravel
Add our service provider to config/app.php
:
'providers' => [ /// ... MenaraSolutions\FluentLaravel\Providers\LaravelServiceProvider::class, /// ... ],
Create a config file (config/fluent.php
):
$ php artisan vendor:publish
Add your Fluent API key and application ID in this config file and you are ready to run!
Uploading original texts
You need to submit your original, untranslated texts to Fluent from time to time so that you or your translators
can start working on translations. To do that run scan
command:
$ php artisan fluent:scan -v
This command will scan your src
and resources/views
folders and look for all invocations of __()
, trans()
and @lang()
.
Moreover, you will be prompted whether you want to upload your existing translations from resources/lang
folder to Fluent.
Updating language files
Run the following command anytime during development or during your CI/CD pipeline:
$ php artisan fluent:fetch
This command will look for any new translations on Fluent and download them to resources/lang-fluent
folder.
Note
This package will not alter any of your files. This package creates an extra folder in resources/
- lang-fluent
, all new languagae
files will be stored here.
You can move back to standard translation implementation at any time. Simply comment out our service provider in config/app.php
.