[PEAR-BUG] Req #5256 [Asn->WFx]: No way to fetch all matching languages

[email protected]
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at http://pear.php.net/bugs/bug.php?id=5256&edit=1

 ID:               5256
 Updated by:       [email protected]
 Reported By:      o dot persson at gmail dot com
 Summary:          No way to fetch all matching languages
-Status:           Assigned
+Status:           Wont fix
 Type:             Feature/Change Request
 Package:          I18Nv2
 Operating System: Debian GNU/Linux
 PHP Version:      5.0.5
 Assigned To:      mike
 Roadmap Versions: 
 New Comment:

-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.


Previous Comments:
------------------------------------------------------------------------

[2005-08-31 08:57:08] 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);
     }

     /**

------------------------------------------------------------------------


-- 
Edit this bug report at http://pear.php.net/bugs/bug.php?id=5256&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.