Download the PHP package salesrender/plugin-component-translations without Composer

On this page you can find all versions of the php package salesrender/plugin-component-translations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package plugin-component-translations

salesrender/plugin-component-translations

Internationalization (i18n) component for SalesRender plugins, providing JSON-based text localization with CLI tools for managing translation files.

Overview

This component implements a complete translation system for the SalesRender plugin ecosystem. It enables plugins to support multiple languages by storing translations in structured JSON files organized by categories and source strings.

The Translator class acts as the central entry point: it loads locale-specific JSON files, resolves translated strings with optional parameter interpolation, and falls back to the default language when a translation is missing. The component also ships with Symfony Console commands that automate the creation and synchronization of translation files by statically analyzing your plugin source code for Translator::get() calls.

Translation files are stored in the translations/ directory at the project root (resolved relative to Composer's autoloader). Each file is named using the xx_YY locale format (e.g., ru_RU.json, en_US.json) and contains a JSON structure grouping translations by category.

Installation

Requirements

Key Classes

Translator

Namespace: SalesRender\Plugin\Components\Translations

The main static class for configuring and retrieving translations.

Methods

Method Signature Description
config static config(string $default): void Initializes the translator with a default locale (e.g., ru_RU). Must be called before any other method.
get static get(string $category, string $message, array $params = []): string Returns a translated string for the given category and message key. Supports parameter interpolation via {key} placeholders. Falls back to default language, then to the raw $message string.
setLang static setLang(string $lang): void Sets the current language. Only applies if the language exists in the available languages list. Accepts both en_US and en-US formats.
getLang static getLang(): string Returns the currently active language code.
getDefaultLang static getDefaultLang(): ?string Returns the default language code, or null if not configured.
getLanguages static getLanguages(): array Returns an array of all available language codes (discovered from translation files plus the default language).

Helper

Namespace: SalesRender\Plugin\Components\Translations\Components

Utility class for path resolution and language discovery.

Methods

Method Signature Description
getTranslationsPath static getTranslationsPath(): Path Returns a Path object pointing to the translations/ directory at the project root (resolved via Composer's ClassLoader).
getLanguages static getLanguages(): array Scans the translations directory and returns an array of available locale codes (filenames matching the xx_YY pattern).

CrawlerCommand (abstract)

Namespace: SalesRender\Plugin\Components\Translations\Commands

Abstract Symfony Console command that provides the core logic for extracting translatable strings from source code. It uses nikic/php-parser to parse all PHP classes under the SalesRender\Plugin namespace and finds every Translator::get('category', 'message') call.

Methods

Method Signature Description
crawl protected crawl(): array Parses all project classes and extracts Translator::get() calls. Returns an associative array [category => [message => true]].
asJson protected asJson(array $data): string Converts a translation scheme array into a pretty-printed JSON string.
schemeToExport protected schemeToExport(array $scheme): array Transforms the internal scheme format into the export format with source/translated pairs.

LangAddCommand

Namespace: SalesRender\Plugin\Components\Translations\Commands

Symfony Console command registered as lang:add. Creates a new translation file for a specified locale by crawling the source code for translatable strings.

Usage:


LangUpdateCommand

Namespace: SalesRender\Plugin\Components\Translations\Commands

Symfony Console command registered as lang:update. Synchronizes all existing translation files with the current source code, preserving existing translations and creating .old.json backups when changes are detected.

Usage:

Usage

Basic Configuration

Configure the translator in your plugin's bootstrap.php file:

Retrieving Translations

Use Translator::get() with a category and a message key:

Switching Languages at Runtime

Using with Plugin Info

Translations are commonly used with lazy-evaluated closures for plugin metadata so that the language can be resolved at request time:

Using in Batch Handlers

The batch component sets the language from the batch context before processing:

Translation File Format

Translation files are stored in the translations/ directory at the project root:

JSON Structure

Each top-level key is a category (the first argument to Translator::get()). Each category contains an array of objects with:

Parameter Interpolation

Parameters are referenced with {key} syntax in both the source and translated strings:

CLI Commands

Adding a New Language

Creates translations/en_US.json with all discovered translatable strings and empty translated values. The locale must match the xx_YY format (e.g., en_US, ru_RU, de_DE). The command fails if the file already exists.

Updating Existing Translations

Scans all source code under the SalesRender\Plugin namespace, then for each existing translation file:

Configuration

The translator requires a single configuration call before use:

The locale must follow the xx_YY format (ISO 639-1 language code + underscore + ISO 3166-1 alpha-2 country code). Hyphens are automatically converted to underscores.

Calling any method (get, getLang, setLang, getLanguages) before config() throws a RuntimeException with the message "Translator was not configured".

API Reference

Translator

Helper

CLI Commands

Command Arguments Description
lang:add lang (required) -- Locale code in xx_YY format Creates a new translation JSON file
lang:update none Synchronizes all translation files with the current source code

Dependencies

Package Version Purpose
nikic/php-parser ^4.3 Static analysis of PHP source code to extract Translator::get() calls
symfony/console ^5.0 CLI command infrastructure (lang:add, lang:update)
haydenpierce/class-finder ^0.4.0 Discovering classes under the SalesRender\Plugin namespace for crawling
xakepehok/path ^0.2 Filesystem path resolution for the translations directory
adbario/php-dot-notation ^2.2 Dot notation access to parsed PHP AST nodes during source code crawling

See Also


All versions of plugin-component-translations with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
ext-json Version *
nikic/php-parser Version ^4.3
symfony/console Version ^5.0
haydenpierce/class-finder Version ^0.4.0
xakepehok/path Version ^0.2
adbario/php-dot-notation Version ^2.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package salesrender/plugin-component-translations contains the following files

Loading the files please wait ...