<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
salesrender / plugin-component-translations example snippets
use SalesRender\Plugin\Components\Translations\Translator;
// Set the default language for the plugin
Translator::config('ru_RU');
use SalesRender\Plugin\Components\Translations\Translator;
// Simple translation
$name = Translator::get('info', 'PLUGIN_NAME');
$description = Translator::get('info', 'PLUGIN_DESCRIPTION');
// Translation with parameter interpolation
$label = Translator::get('autocomplete', 'DYNAMIC_VALUE #{value}', ['value' => $query]);
$range = Translator::get('autocomplete', 'GROUP_FROM_TO ({min}-{max})', ['min' => 1, 'max' => 10]);
// Using in form definitions
$title = Translator::get('settings', 'Settings');
$fieldLabel = Translator::get('settings', 'Answer prefix');
$error = Translator::get('settings', 'Field can not be empty');
use SalesRender\Plugin\Components\Translations\Translator;
// Set language for the current request
Translator::setLang('en_US');
// Hyphenated format is also accepted (automatically converted to underscore)
Translator::setLang('en-US');
// Get the active language
$currentLang = Translator::getLang(); // e.g., "en_US"
// Get all available languages
$languages = Translator::getLanguages(); // e.g., ['ru_RU', 'en_US']
use SalesRender\Plugin\Components\Info\Info;
use SalesRender\Plugin\Components\Info\PluginType;
use SalesRender\Plugin\Components\Info\Developer;
use SalesRender\Plugin\Components\Translations\Translator;
Translator::config('ru_RU');
Info::config(
new PluginType(PluginType::MACROS),
fn() => Translator::get('info', 'PLUGIN_NAME'),
fn() => Translator::get('info', 'PLUGIN_DESCRIPTION'),
new PluginPurpose(
new MacrosPluginClass(MacrosPluginClass::CLASS_HANDLER),
new PluginEntity(PluginEntity::ENTITY_ORDER)
),
new Developer('LeadVertex', '[email protected]', 'leadvertex.com')
);
use SalesRender\Plugin\Components\Translations\Translator;
// Set the language passed from the batch request
Translator::setLang(str_replace('-', '_', $batch->getLang()));
// All subsequent Translator::get() calls will use this language
$errorMessage = Translator::get('batch', 'Failed to create waybill');
public static function config(string $default): void
public static function get(string $category, string $message, array $params = []): string
public static function setLang(string $lang): void
public static function getLang(): string
public static function getDefaultLang(): ?string
public static function getLanguages(): array
public static function getTranslationsPath(): \XAKEPEHOK\Path\Path
public static function getLanguages(): array
bash
php console lang:add en_US
project-root/
translations/
ru_RU.json
en_US.json
bash
php console lang:add en_US
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.