basz / SlmLocale

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

"de-DE" as alias for "de" when using HTTP Accept-Language #42

Closed glen-84 closed 6 years ago

glen-84 commented 10 years ago

Config:

// SLM locale.
'slm_locale' => array(
    'default' => 'en',
    'supported' => array('en', 'de', 'ko'),
    'strategies' => array(
        'uripath',
        'acceptlanguage'
    )
)

Works:

de,de-DE;q=0.94,en-ZA;q=0.89,en;q=0.83,zh-CN;q=0.78,zh;q=0.72,en-GB;q=0.67,en-US;q=0.61,fr-FR;q=0.56,fr;q=0.5,es-ES;q=0.44,es;q=0.39,it-IT;q=0.33,it;q=0.28,nl-NL;q=0.22,nl;q=0.17,en-za;q=0.11,en-us;q=0.06

Doesn't:

de-DE,de;q=0.94,en-ZA;q=0.89,en;q=0.83,zh-CN;q=0.78,zh;q=0.72,en-GB;q=0.67,en-US;q=0.61,fr-FR;q=0.56,fr;q=0.5,es-ES;q=0.44,es;q=0.39,it-IT;q=0.33,it;q=0.28,nl-NL;q=0.22,nl;q=0.17,en-za;q=0.11,en-us;q=0.06

How do I make it so that "de-DE" maps to "de"? (and "en-XX" maps to "en", etc.)

juriansluiman commented 10 years ago

@glen-84 a locale is "de-DE" and not "de". You'd rather support "en-US", "en-GB" and "de-DE" and so on. Then you alias "en" to "en-US" and "de" to "de-DE". This is the way SlmLocale is tested and should work. I am not sure the inverse can also be done.

Can you test that setup please?

juriansluiman commented 10 years ago

@glen-84 have you tested this already?

glen-84 commented 10 years ago

@juriansluiman,

So if I want to support "generic" English I have to list:

en-AU en-BZ en-CA en-GB en-IE en-IN en-JM en-MY en-NZ en-PH en-SG en-TT en-US en-ZA en-ZW

... seems a bit crazy.

And how do I alias these to "en"?

juriansluiman commented 10 years ago

What's the common header form someone accepting en-NZ? I would assume there is somewhere en-US or en-GB located. Point is, all those locales do talk English in general, but I detail they're all a bit different. That's why you need to be able to distinguish between all of them.

A concept not implemented in SlmLocale is something I'd call "alternatives". You might want to indicate all en-* locales are mapped to en-US for example. Mind you cannot support en-US and en-GB at the same time anymore, but you're able to define an alternative then. It's not really the same as the concept of an alias. However, I don't think it is a real problem in practise as most of your list are accepting the US or GB part anyhow. Thoughts?

svycka commented 6 years ago

This should be possible now if not please create new issue.