PHP code example of sirgrimorum / transarticles

1. Go to this page and download the library: Download sirgrimorum/transarticles library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sirgrimorum / transarticles example snippets


return [
    // Eloquent model used to store articles
    'default_articles_model' => \Sirgrimorum\TransArticles\Models\Article::class,

    // Database column that stores the locale code
    'default_lang_column' => 'lang',

    // Model scope used to find a single article
    'default_findarticle_function_name' => 'findArticle',

    // Model scope used to find a collection of articles
    'default_findarticles_function_name' => 'findArticles',

    // JavaScript global variable for exposed articles
    'default_base_var' => 'translations',
];

\Sirgrimorum\TransArticles\Models\Article::create([
    'scope'     => 'homepage',
    'nickname'  => 'hero_title',
    'lang'      => 'en',
    'content'   => '<h1>Welcome to our site</h1>',
    'activated' => true,
]);

use Sirgrimorum\TransArticles\Facades\TransArticles;

// Returns content for the current locale (or fallback)
$html = TransArticles::get('homepage.hero_title');

// Expose a scope as a <script> tag
$script = TransArticles::getjs('homepage');

echo trans_article('homepage.hero_title');

TransArticles::get(string $nickname): string

TransArticles::getjs(
    string $scope,      // Scope to expose (or 'scope.nickname' for a single article)
    string $basevar = '' // JS global variable (defaults to config 'default_base_var')
): string

trans_article(string $nickname): string
bash
php artisan migrate
bash
php artisan vendor:publish --provider="Sirgrimorum\TransArticles\TransArticlesServiceProvider" --tag=config