PHP code example of codewiser / polyglot

1. Go to this page and download the library: Download codewiser/polyglot 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/ */

    

codewiser / polyglot example snippets


/**
 * Register the Polyglot gate.
 *
 * This gate determines who can access Polyglot in non-local environments.
 *
 * @return void
 */
protected function gate()
{
    Gate::define('viewPolyglot', function ($user) {
        return in_array($user->email, [
            '[email protected]',
        ]);
    });
}

'sources' => [
    [
        '       resource_path('views')
        ],
        'exclude' => [],
    ]
],

'locales' => [
    'en' => ['en_US', 'en_US.utf8', 'en_US.UTF-8'] 
    'it' => ['it_IT', 'it_IT.utf8', 'it_IT.UTF-8'], 
    'es' => ['es_ES', 'es_ES.utf8', 'es_ES.UTF-8'],
],

class AcceptLanguage
{
    public function handle(Request $request, Closure $next)
    {
        app()->setLocale($request->getPreferredLanguage(Polyglot::getLocales()));

        return $next($request);
    }
}

'enabled' => env('POLYGLOT_GETTEXT', true),

'sources' => [
  [
    'text_domain' => 'frontend',
    '],
    'exclude' => resource_path('views/admin'),
  ],
  [
    'text_domain' => 'backend',
    '

Lang::setTextDomain('frontend');

gettext(string $message): string

ngettext(string $singular, string $plural, int $count): string

pgettext(string $context, string $message): string

npgettext(string $context, string $singular, string $plural, int $count): string

// The message will be shown at test page only.
echo gettext('Hello world');
shell
php artisan polyglot:install
shell
php artisan polyglot:publish
json
{
    "scripts": {
        "post-update-cmd": [
            "@php artisan polyglot:publish --ansi"
        ]
    }
}
shell
php artisan polyglot:collect
shell
php artisan polyglot:compile