dev-master
9999999-devOpen plugin for using multilanguage on ZF2 applications
GPL3
The Requires
- php >=5.3.0
- zendframework/zendframework 2.3.*
by Daniel Tome
Open plugin for using multilanguage on ZF2 applications
zf2Languages: Open plugin for using multilanguage on ZF2 applications Copyright (C) 2015 SREd Servei de Recursos Educatius http://www.sre.urv.cat/, (*1)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version., (*2)
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details., (*3)
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/., (*4)
Daniel Tomé Fernåndez (danieltomefer@gmail.com) as a worker on SREd (http://www.sre.urv.cat/), (*5)
This plugin help us using multilanguage on our Zend Framework 2 application. It provides us an API and a config. This config will be fundamental for correct working., (*6)
To install this module you must follow this steps:, (*7)
1 - In your composer.json
you must write:, (*8)
"require": { "sred/zf2languages" : "dev-master" },
and
"autoload": { "psr-4":{ "zf2languages\\" : "vendor/sred/zf2languages" } }
2 - Then you must run the following command line: composer update
, (*9)
To use this plugin you must make a config like the following:, (*10)
'languages' => array( 'all' => array( 'ca' => 'Catalan', 'es' => 'Spanish', 'en' => 'English', ), 'default' => array( 'ca', ), ),
'browser' => array( 'set_lang_from_browser' => true, ),
In all
array you must have the key and the translation of this key. For example: 'en' => 'English'.
In default
language you must have the key of the default language.
In browser
array you must have defined if you want to get language from browser configuration or not., (*11)
And the last step is adding the module to your module's configuration application.conf.php
:, (*12)
'modules' => array( 'zf2languages', ),
It is very easy using this plugin. We provide a Helper and a Plugin so in the view or controllers you only must write :
$this->languages()->method()
., (*13)
If you want to use it out of view and controllers, we provide a Factory of Languages. So you only must write:, (*14)
$languages = $serviceManager->get('languages');
and you'll have all the functions available., (*15)
isDefaultLanguage($lang)
-> This method will return if parameter is equals to default language defined on config(key)., (*16)
getDefaultLanguage()
-> This method will return the default language defined on our config file., (*17)
getLanguagesCodes()
-> This method will return the array defined on our config with the key 'all'. (keys and translations)., (*18)
translate($lang)
-> Given a key of a language, this method will return the translation of that key., (*19)
isValid($lang)
-> Given a key this method will return if this language is defined or not., (*20)
updateCookie($serviceManager, $lang)
-> This method will help us to create a cookie with language defined on our application., (*21)
getLocaleForSession($serviceManager)
-> This method will give to us the language depending on the language on our browser or cookie., (*22)
Open plugin for using multilanguage on ZF2 applications
GPL3