PHP code example of solumdesignum / package-translator-loader

1. Go to this page and download the library: Download solumdesignum/package-translator-loader 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/ */

    

solumdesignum / package-translator-loader example snippets




declare(strict_types=1);

return [
    'segment' => 1
];



declare(strict_types=1);

namespace SolumDeSignum\ThemeManager;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use SolumDeSignum\PackageTranslatorLoader\PackageTranslatorLoader;

class ExampleServiceProvider extends ServiceProvider
{
    /**
     * @var PackageTranslatorLoader
     */
    private PackageTranslatorLoader $packageTranslatorLoader;

    /**
     * ExampleServiceProvider constructor.
     *
     * @param Application $app
     */
    public function __construct(Application $app)
    {
        parent::__construct($app);
        $this->packageTranslatorLoader = new PackageTranslatorLoader(
            $this->app,
            [
                'translator' => 'theme-manager.translator',
                'nameSpace' => 'solumdesignum/theme-manager',
                'packageRootPath' => __DIR__ . '/..',
                'loadLangPath' => '/../resources/lang',
                'loaderLangPath' => '/resources/lang',
            ]
        );
    }
}



declare(strict_types=1);

/**
 * Internal package translations
 * Even exceptions for both examples
 */
 
/**
 * Internal Translator instance
 * inside function get() should pass package name with translation key (package.translation-key)
 */
    $this->packageTranslatorLoader->trans()
        ->get('theme-manager.invalid_argument_exception');
        
/**
 * Helper: can be used in Blade, Controllers, Models, Services and etc...
 * Inside first key must pass name of translator 
 * Inside second key must pass package name with translation key (package.translation-key)
 */
translator(
    'theme-manager.translator',
    'theme-manager.invalid_argument_exception'
);