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: 2021-11-11 11:15 UTC
Votes:14
Avg. Score:4.0 ± 0.9
Reproduced:11 of 12 (91.7%)
Same Version:4 (36.4%)
Same OS:3 (27.3%)
From: i at walkinraven dot name Assigned:
Status: Open Package: I18N and L10N related
PHP Version: 5.3.2 OS: Ubuntu 10.04 LTS
Private report: No CVE-ID: None
 [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

Pull Requests

Pull requests:

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)
 [2017-10-24 07:52 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: stas +Assigned To:
 [2021-11-11 11:15 UTC] nikic@php.net
-Package: intl +Package: I18N and L10N related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 14:01:29 2024 UTC