PHP code example of a21 / lexicon-client

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

    

a21 / lexicon-client example snippets


A21\LexiconClient\LexiconClientServiceProvider::class,

return [
    'api_url'      => env('LEXICON_API_URL'),
    'client_code'  => env('LEXICON_CLIENT_CODE'),
    'project_code' => env('LEXICON_PROJECT_CODE'),
    'secret'       => env('LEXICON_CLIENT_SECRET'),
    'environment'  => env('LEXICON_ENVIRONMENT', env('APP_ENV', 'local')),

    'manifest' => base_path('lexicon.json'),

    'output' => [
        'base_path' => env('LEXICON_OUTPUT_BASE_PATH', 'lang'),
        'pattern'   => env('LEXICON_OUTPUT_PATTERN', '{locale}/{relative_path}'),
        'format'    => env('LEXICON_OUTPUT_FORMAT', 'php'),
        'merge'     => env('LEXICON_OUTPUT_MERGE', 'add_missing'),
    ],

    'http' => [
        'timeout'        => 30,
        'import_timeout' => 180,
        'retry_times'    => 2,
        'retry_sleep_ms' => 200,
    ],
];

use Illuminate\Support\Facades\Schedule;

Schedule::command('lexicon:push --group=categories')->dailyAt('02:00');
Schedule::command('lexicon:import --path=lang')->weekly();

use A21\LexiconClient\Extraction\ExtractorRegistryFactory;
use A21\LexiconClient\Extraction\ExtractionRunner;
use A21\LexiconClient\Http\LexiconHttpClient;

$registry = ExtractorRegistryFactory::default();
$registry->register(new MyCustomExtractor()); // ->type() matches manifest `type`

$runner  = new ExtractionRunner($registry);
$entries = $runner->run($definitions, ['groups' => ['catalog']]);

$client = new LexiconHttpClient([
    'api_url'      => config('lexicon.api_url'),
    'client_code'  => config('lexicon.client_code'),
    'project_code' => config('lexicon.project_code'),
    'secret'       => config('lexicon.secret'),
    'environment'  => config('lexicon.environment'),
]);

foreach ($entries as $entry) {
    $client->translate($entry->toTranslatePayload(config('lexicon.project_code')));
}
bash
php artisan vendor:publish --tag=lexicon-config   # -> config/lexicon.php
php artisan lexicon:init                           # -> lexicon.json + .env.example keys
bash
php artisan lexicon:install-ugc-sync --migrate
bash
php artisan lexicon:install-ugc-sync --migrate
bash
php artisan lexicon:extract                          # read-only preview
php artisan lexicon:push --group=categories --dry-run
php artisan lexicon:push --group=categories
php artisan lexicon:sync --entity=category