basz / SlmLocale

Auto detection of locale through different strategies for Zend Framework 2
Other
68 stars 34 forks source link

How to use it ? #15

Closed ghost closed 11 years ago

ghost commented 11 years ago

Hi there i'm using a localeResolver class with acceptLanguage strategy:

http://pastebin.com/ZehPq4Ke

'localeResolver' => function ($sm) { $service = new Service\LocaleResolver(); $service->resolveLocale($sm->get('request')); return $service; },

1 - How to use slmlocale instead ?

Moreover i'd like to detect locale from router (routeMatch) because first segment (lang) of uri is not mandatory and sometimes empty. In that case i have to get lang by default that is set into route. 2 - Do you think is it correct or do i have to use UriPathStrategy ?

3 - What's the correct way to pass into url ? locale or language ?

I read somewhere that now the correct locale format is en_US_utf8 . I that mean that i have to pass into url this stuff ? http://myhost/en_US_utf8/...

It's not very clear for me.

juriansluiman commented 11 years ago

SlmLocale is a module you have to install by for example composer or with a git submodule. Then you enable the module in your application.config.php.

Use SlmLocale by placing a copy of the slmlocale.global.php.dist inside your config/autoload folder and rename it to slmlocale.global.dist. You can configure your supported set of locales and aliases of that locale (so for example "fr" hints to "fr-FR. In the "strategies" array you list all the strategies you want to have.

At this moment you probably want the uri path strategy, but that one is not finished yet. There are some difficulties with it, so it is better to use the cookie, query or http header strategy. You can follow the progress of the uri path strategy here.

There is also a set of view helpers requested now here where you can assemble localized urls in your application.

ghost commented 11 years ago

I know how to install it, i did it but now i'm looking for at least 1 minimal example to use it.

it seems it's too early to use it so i'll switch to slmLocale later, at the end of the dev.

Thank you @juriansluiman

juriansluiman commented 11 years ago

Yes, you are correct it's still in early stage of development. I also have an open branch for documentation: https://github.com/juriansluiman/SlmLocale/tree/feature/docs/docs where you can already see something where it's heading to.