Zend Framework 2 module to create multilingual applications
return array(
'jpg-locale' => array(
'adapter' => array( ... ),
'handlers' => array( ... ),
)
);
adapter
Allows to choose one of the available locale adaptershandlers
The handlers we are going to use to detect the locale.
Currently we've got the following handlers:
Path
- Looks for the locale in the URL path. This is done automatically so the application routes stay untouched. If no locale is found it will load the default locale so no redirects are needed improving SEO. As an example http://yourdomain.com/en/ will load the english locale.Query
Looks for a query parameterlocale=
which will define the locale to use. For example http://yourdomain.com/?locale=en-US will load theen_US
locale.Subdomain
This one searches in your subdomain. For example: http://en-us.yourdomain.com/ will loaden_US
locale.
Just set the ones you wish to use. I really can't find a reason for having several handlers, but I left it up to you to add multiple handlers.
The following example adds the Query
and Subdomain
handlers
...
'handlers' => array(
'Query',
'Subdomain'
)
...
By default the parameter searched in the Query
handler is locale. Handlers can be tweaked with otions. For example, if you prefere to use lang you could set it as follows:
...
'handlers' => array(
array(
'type' => 'Query',
'options' => array (
'param' => 'lang'
),
),
'Subdomain'
)
...
Currently there is only one adapter:
Config
- uses local cofiguration files
...
'adapter' => array(
'type' => 'Config',
'options' => array(
'default' => 'en_US',
'locales' => array(
'en_US' => array(
'english_name' => 'English',
'native_name' => 'English'
),
'es_ES' => array(
'english_name' => 'Spanish',
'native_name' => 'Español'
)
)
)
)
...
The adapter type
is set to Config
as we want to use this adapter. The Config
adapter requires some options
default
(optional) sets the default locale.locales
(mandatory) sets the available locales for our application.english_name
(optional) The english name of the locale.native_name
(optional) The native name of the locale.
If english_name
and/or native_name
are not set the INTL extension will try to figure them out. However, if INTL extension is not set in your system it will throw exceptions.
- Database Adapter
- Doctrine Adapter