Download the PHP package pyrsmk/translator without Composer
On this page you can find all versions of the php package pyrsmk/translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pyrsmk/translator
More information about pyrsmk/translator
Files in pyrsmk/translator
Package translator
Short Description Simple translation tool for CLI/HTTP environments
License MIT
Informations about the package translator
Translator 2.0.4
Translator is a small I18N/L10N library, based on Chernozem (we advise you to read its documentation). Here's the available options through Chernozem :
- client_locales : the client's locales
- delimiters : set the start/end delimiter for string replacement (default :
['start' => '{', 'end' => '}']
) - translations : the loaded translations
Install
Pick up the source or install it with Composer :
Basics
Translator is available for a website (Translator\Http
) and a CLI application (Translator\Cli
). For the next examples, we'll use Translator\Http
.
First, we need to define the default locale at instantiation. This locale will be used when no client's locale is supported by your application.
Translator will find what locale to use by comparing the client's locales and the defined available locales (based on the loaded translations)
If needed, you can force Translator to use a specific locale :
And you can retrieve what locale Translator will use for its translations with :
Load your translations files
Translator doesn't implement adapters to load your files, it just expect the name of the locale and the translation strings. Then you can use any library you want to load your files or do it by hand. Here's how to do it with JSON :
Translate!
Simply :
Translator can also replace strings in your translations :
Normalize a locale
If needed, you can normalize any locale you want with :
License
This library is released under the MIT license.