sirgrimorum/transarticles

Localization using db table as source for translated text

1.2.14 2020-09-29 17:08 UTC

This package is auto-updated.

Last update: 2024-11-11 19:21:00 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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

License

The MIT License (MIT). Please see License File for more information.