Download the PHP package stantabcorp/i18n without Composer
On this page you can find all versions of the php package stantabcorp/i18n. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stantabcorp/i18n
More information about stantabcorp/i18n
Files in stantabcorp/i18n
Package i18n
Short Description Internationalization library for PHP
License proprietary
Homepage https://github.com/stantabcorp/i18n
Informations about the package i18n
i18n
Internationalization library for PHP This library allows you to translate your website with ini files, Auto Detecting the language and much more!
Documentation
Information
i18n will create a folder named "i18n" please make sure it is readable
Installation
- Via composer:
composer require stantabcorp/i18n
- Via manually download and install
Initialization
In the i18n constructor your must-have 3 parameters:
- The language you want to display your website or true to use AutoDetect
- The default language
- An array of available languages
- An array of options
Example: Without AutoDetect:
This will set the language to en
(English), set the default language to en
(English) and set that en
(English) and fr
(French) are available
With AutoDetect:
This will set the language to AutoDetect, set the default language and set available language for AutoDetect
AutoDetect, use the Accept-Language HTTP Header to determine the best matching locale to use.
Usage
In order to get a translation you just need to:
If you want to use sections in your ini file use the following syntax:
If you want to get the current language:
You want to change the language?
You don't want to use sprintf
?! No problem:
Want to change the translation folder on the fly?
Want to get the active folder?
Want to set the available languages?
Want to get the available languages?
Now, let set and get the default language
File syntax
Sections are supported by i18n, see options to enable it
Example file:
Options
The fourth parameter when initializing the i18n class is an array.
Accepted values are:
error
, a boolean to enable or disable error throwingsections
, a boolean to enable or not sections in the ini filespath
, to set a path for the translations
Twig Extension
i18n provide a simple Twig extension. To enable it, simply add a new extension to twig:
In order to use it in a twig template, simply call (with the same syntax for section):