Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.11.4

Request #5256 No way to fetch all matching languages
Submitted: 2005-08-31 12:57 UTC
From: o dot persson at gmail dot com Assigned: mike
Status: Wont fix Package: I18Nv2
PHP Version: 5.0.5 OS: Debian GNU/Linux
Roadmaps: (Not assigned)    
Subscription  


 [2005-08-31 12:57 UTC] o dot persson at gmail dot com
Description: ------------ Today you can fetch the best matched language. But there's no way to fetch the rest of the languages. This would be very interesting in some cases -- eg. when there's no translation available for the best matched language one can fall back to the second best. Attached is a small patch (against the current CVS version). Feel free to do whatever you like. I think it would be a great feature. ;) Test script: --------------- Index: ../components/PEAR/I18Nv2/Negotiator.php =================================================================== --- ../components/PEAR/I18Nv2/Negotiator.php (revision 59) +++ ../components/PEAR/I18Nv2/Negotiator.php (working copy) @@ -274,6 +274,20 @@ } /** + * Find Language matches + * + * @access public + * @return string + * @param array $langs + */ + function getLanguageMatches($langs = null) + { + $languages = $this->_getMatches($langs, $this->_acceptLanguage, + $this->_defaultLanguage); + return array_unique($languages); + } + + /** * Find locale match * * @access public @@ -303,13 +317,24 @@ if (!$haystack) { return $default; } + $matches = $this->_getMatches($needle, $haystack); + return (count($matches) > 0) ? array_shift($matches) : $default; + } + + /** + * Return an array of matched values from first and second parameter. + * + * @access private + * @return string + * @param array $needle + * @param array $haystack + */ + function _getMatches($needle, $haystack) + { if (!$needle) { - return array_shift($haystack); + return $haystack; } - if ($result = array_shift($a = array_intersect($haystack, $needle))) { - return $result; - } - return $default; + return array_intersect($haystack, $needle); } /**

Comments

 [2011-08-19 19:08 UTC] stelianm (Stelian Mocanita)
-Status: Assigned +Status: Wont fix
Hello and thank you for the patch. Unfortunately we decided not to address any other requirement for this package, as it was moved to PECL Intl package available at http://php.net/intl. We will however address bugs and security concerns.