Download the PHP package lantosbro/cli-localizer without Composer
On this page you can find all versions of the php package lantosbro/cli-localizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lantosbro/cli-localizer
More information about lantosbro/cli-localizer
Files in lantosbro/cli-localizer
Package cli-localizer
Short Description A library for localization in CLI applications
License MIT
Homepage https://github.com/LantosBro/cli-localizer
Informations about the package cli-localizer
CliLocalizer
CliLocalizer is a PHP library for easy localization in CLI applications with support for multiple translation file formats (JSON, YAML, PHP(Array) and MO).
Installation
You can install the package via composer:
Requirements
- PHP 7.4 or higher
- PHP YAML extension
- PHP Gettext extension
To install the YAML extension:
To install the Gettext extension:
Then add extension=yaml.so and extension=gettext.so to your php.ini file.
Usage
Configuration
You must specify the path to your translations directory and the format of your translation files when initializing the Translator. Supported formats are:
- JSON ('json')
- YAML ('yaml')
- PHP ('php')
- MO ('mo')
Create translation files in your specified translations directory using the chosen format.
Example translation files:
JSON (en_US.json):
YAML (en_US.yaml):
PHP (en_US.php):
For MO files, you need to compile them from PO files using tools like msgfmt. The structure should be similar to other formats, with keys being the original strings and values being the translations.
The Translator will attempt to load translations in the following order:
- The specified locale (e.g., 'ru_RU')
- The language code of the specified locale (e.g., 'ru')
- The fallback locale (default is 'en_US')
Ensure that you have at least a translation file for your fallback locale.
License
The MIT License (MIT). Please see License File for more information.
All versions of cli-localizer with dependencies
ext-yaml Version *
ext-json Version *