php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #59430 Why Locale::acceptFromHttp can't Returns with an Array?
Submitted: 2010-09-20 05:17 UTC Modified: 2010-09-30 20:35 UTC
Votes:13
Avg. Score:4.0 ± 1.0
Reproduced:10 of 11 (90.9%)
Same Version:4 (40.0%)
Same OS:3 (30.0%)
From: i at walkinraven dot name Assigned: stas
Status: Assigned Package: intl (PECL)
PHP Version: 5.3.2 OS: Ubuntu 10.04 LTS
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-09-20 05:17 UTC] i at walkinraven dot name
Description:
------------
Locale::acceptFromHttp could only returns with a string. But HTTP Accept-Language could offer more than one language tag with priority. Why not to return an number-ordered-array like:

array
(
  0 => language tag 1,
  1 => language tag 2,
  ...
)

Ordered with priority offered by HTTP?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-22 22:10 UTC] thflori at gmail dot com
At least this yes. But in each application we will have a code that looks similar to this:

$supportedLanguages = ['de_DE','en_US'];

foreach (Loacle::acceptFromHttp as $locale) {
  if (in_array($locale, $supportedLocales)) {
    return $locale;
  }
}
return $defaultLocale;

Why a acceptFromHttp if it is useless? The best matching is not useful at all. A list of matching locales is at least useful. But even better will be a function that gives the locale we want to use:
public static function acceptFromHttp($header, $supportedLocales, $defaultLocale)
 
PHP Copyright © 2001-2016 The PHP Group
All rights reserved.
Last updated: Sun May 01 06:01:52 2016 UTC