Zend Framework tarayıcı dil (ler) belirler?

4 Cevap php

Ben zamanla topladığı çeşitli PHP yardımcı fonksiyonları ile oldukça büyük eski kütüphane çözülmesi duyuyorum. Ben mümkün olduğunca bu fonksiyonların gibi birçok Zend Framework tabanlı değiştirmeleri için arıyorum.

Benim ilk aday olabilir büyük bir listeden kullanıcıların bulunuyor most preferred browser language döndüren bir fonksiyondur http_accept_language.

ZF Bunun için bir işlevi var mı?

I Zend_Translate şekilde tarayıcı dili tespit etmek mümkün olduğunu biliyoruz, ama aslında dil dize almak için kamuya açık bir işlev göremiyorum.

4 Cevap

Buyrun:

$locale = new Zend_Locale();

// if locale is 'de_AT' then 'de' will be returned as language
print $locale->getLanguage();

// if locale is 'de_AT' then 'AT' will be returned as region
print $locale->getRegion();

Zend_Locale Bu konuda, yardım etmek gerekir.

Sayfadaki örnekler ve açıklamalara bakınız Using Zend_Locale (quoting):

For most situations, new Zend_Locale() will automatically select the correct locale, with preference given to information provided by the user's web browser.


And there are a couple more details later on that page (quoting) :

The search algorithm used by Zend_Locale for automatic selection of a locale uses three sources of information:

1. const Zend_Locale::BROWSER - The user's Web browser provides information with each request, which is published by PHP in the global variable HTTP_ACCEPT_LANGUAGE. if no matching locale can be found, then preference is given to ENVIRONMENT and lastly FRAMEWORK.

2. const Zend_Locale::ENVIRONMENT - PHP publishes the host server's locale via the PHP internal function setlocale(). If no matching locale can be found, then preference is given to FRAMEWORK and lastly BROWSER.

3. const Zend_Locale::FRAMEWORK - When Zend Framework has a standardized way of specifying component defaults (planned, but not yet available), then using this constant during instantiation will give preference to choosing a locale based on these defaults. If no matching locale can be found, then preference is given to ENVIRONMENT and lastly BROWSER.

(Advice : go read that page -- I will not copy-paste everything there is to read ^^ )


Edit : And here's the portion of code that illustrates my comment :

$locale = new Zend_Locale();
var_dump($locale->getLanguage());
var_dump($locale->getRegion());
die;

Bana verir:

string(2) "fr" 
bool(false) 

Bir bölge belirtmeden Eh, benim tarayıcı ^ ^, fransız istiyor

Ben her iki cevapları upvoted ettik. Ile dil almak için bir alternatif olarak Zend_Locale dikkate

Yerine sadece dil kodu ('tr') ve ('tr_TR' gibi dil kodu ve bölge kodu) ilk full yereli almak için Zend_Locale() zorlamak için bir olasılık var mı? Değilse onlar tam bir yerel gerekir, çünkü bu para işlemek için bir sorun.

Nasıl bu sorunu ele? Ben henüz bu sorun için herhangi bir kabul edilebilir bir çözüm bulamadık ve bu Zend_Locale için bir görev olmalıdır gibi benim için örneğin _prepareLocale($locale, $strict = false) olarak görünüyor.