sirgrimorum / transarticles
Localization using db table as source for translated text
Requires
- php: >=7.0
- konekt/laravel-migration-compatibility: >1.3
- laravel/framework: >=5.4
- orangehill/iseed: >2.2
Requires (Dev)
- phpunit/phpunit: >=5.4.3
README
Localization using a datablase table for Laravel 5.6. Include a function to add Translation form DB to javascript.
Install
Via Composer
$ composer require :sirgrimorum/transarticles
Create Table
$ php artisan migrate
OPTIONAL: Publish configuration file
$php artisan vendor:publish --tag=config
Usage
Bring a translated article
$text = TransArticles::get("scope.nickname");
OR
$text = trans_article("scope.nickname");
Articles to JavaScript
Load javascript object with all translations of a given scope
{!! TransArticles::getjs('scope') !!} <script> (function() { alert(translations.scope.nickname); })(); </script>
Load javascript object with translated article
{!! TransArticles::getjs('scope.nickname') !!} <script> (function() { alert(translations.scope.nickname); })(); </script>
Blade directives
Bring a translated article using the Blade directive
@transarticles("scope.nickname")
Load javascript object with all translations of a given scope using the Blade directive
@transarticles_tojs('scope') <script> (function() { alert(translations.scope.nickname); })(); </script>
Load javascript object with translated article using the Blade directive
@transarticles_tojs('scope.nickname') <script> (function() { alert(translations.scope.nickname); })(); </script>
When using blade directives, remember to clear de view:cache after each change in the articles table:
$php artisan view:clear
Seeding
TransArticles installs orangehill/iseed to create seed files from the DataBase data. There are 2 new commands:
To create seed files from the Articles table:
$php artisan transarticles:createseed
To create seed files from ALL the tables in de DataBase except the migrations table:
$php artisan transarticles:createseed --all
To create seed files from ALL the tables in de DataBase except the migrations table without suffix and forcing overwrite of prior seed files:
$php artisan transarticles:createseed --all --force
Security
If you discover any security related issues, please email andres.espinosa@grimorum.com instead of using the issue tracker.
Credits
- SirGrimorum link-author
- Grimorum Ltda. link-contributors
License
The MIT License (MIT). Please see License File for more information.