This module provides routes for i18n features and a list of Languages, Countries and Regions translated to all languages.
- PHP 5.4 or greater
- Zend Framework 2 framework.zend.com.
Instalation can be done with composer ou manually
For composer documentation, please refer to getcomposer.org.
-
Enter your project directory
-
Create or edit your
composer.json
file with following contents:{ "minimum-stability": "dev", "require": { "los/losi18n": "1.*" } }
-
Run
php composer.phar install
-
Open
my/project/directory/config/application.config.php
and addLosI18n
to yourmodules
- Clone this module LosI18n to your vendor directory
- Enable it in your config/application.config.php like the step 4 in the previous section.
This module needs data from losi18n-data. So you need either to add the module to you project or download individual language files:
-
Enter your project directory
-
Create or edit your
composer.json
file with following contents:{ "minimum-stability": "dev", "require": { "los/losi18n-data": "1.*" } }
-
Run
php composer.phar update
After the LosI18n is installed in your project, use the download console action:
php public/index.php losi18n download
Examples:
mkdir -p vendor/los/losi18n-data/data
php public/index.php losi18n download vendor/los/losi18n-data/data en,en_US,pt,pt_BR
There are 3 formats: php, json and csv. If you need to import the json file, it's located: vendor/los/losi18n-data/data//languages.json vendor/los/losi18n-data/data//countries.json vendor/los/losi18n-data/data//regions.json
$languagesService = $sm->get('losi18n-countries');
// All languages translated to pt_BR
$languages = $countriesService->getAllLanguages('pt_BR');
// All languages in their native names
$languages = $countriesService->getNativeLanguages();
// Brazilian Portuguese in English
$language = $countriesService->getLanguage('pt_BR', 'en);
$countriesService = $sm->get('losi18n-countries');
// All countries translated to English
$countries = $countriesService->getAllCountries('en');
// United States translated to Brazilian Portuguese
$country = $countriesService->getCountry('US','pt_BR');
$regionsService = $sm->get('losi18n-regions');
$regions = $countriesService->getAllRegions('pt_BR');
This module provides 2 routes (but you can use it anywhere).
This los-i18n is a Segment route that accepts a language in both formats (2 or 5 caracters: en or en_US).
For example, the bellow route will produce a route: /en/album /pt_BR/album
'router' => array(
'routes' => array(
'los-i18n' => [
'child_routes' => [
'album' => array(
'type' => 'literal',
'options' => array(
'route' => '/album',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Album',
'action' => 'list'
)
),
...
A route integrated with ZfcAdmin si also provided: /admin/en/album /admin/pt_BR/album
'router' => array(
'routes' => array(
'zfcadmin' => array(
'child_routes' => array(
'los-i18n' => [
'child_routes' => [
'album' => array(
'type' => 'literal',
'options' => array(
'route' => '/album',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Album',
'action' => 'list'
)
),
...
The default language is pt_BR, to change it, just configure the default:
'router' => array(
'routes' => array(
'los-i18n' => [
'options' => array(
'defaults' => array(
'lang' => 'en_UK',
)
),
...