php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76513 locale for day of week
Submitted: 2018-06-21 14:07 UTC Modified: 2018-06-24 10:53 UTC
From: jluc at no-log dot org Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.2.6 OS: linux
Private report: No CVE-ID: None
 [2018-06-21 14:07 UTC] jluc at no-log dot org
Description:
------------
---
From manual page: http://www.php.net/function.strftime
---

"Format the time and/or date according to locale settings. Month and weekday names and other language-dependent strings respect the current locale set with setlocale()."

BUT day of week are allways english, whatever the locale

The given example is :
  setlocale(LC_TIME, "fr_FR");
  echo strftime(" in French %A and");

but the output is not displayed in http://www.php.net/function.strftime

AMOF, output is 
  in French Thursday and Thu

Which is not the expected : "in French Jeudi and Jeu"




Expected result:
----------------
Either documentation is wrong and setlocale is not efficient with dayofweeks names

Either this is a bug

Anyway, the output for this example should be included in the documentation (not only the PHP source) as it's done for other examples.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-21 14:50 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2018-06-21 14:50 UTC] danack@php.net
I can't reproduce this issue. Please could you run on the command line:

```
locale -a | grep fr
```

and also run
```
$result = setlocale(LC_TIME, "fr_FR");
echo strftime(" in French %A and");
var_dump($result);
```
and give the output for both.

The simplest explanation would be that the fr_FR locale is not available on your system for whatever reason.
 [2018-06-23 21:46 UTC] jluc at no-log dot org
-Status: Feedback +Status: Open
 [2018-06-23 21:46 UTC] jluc at no-log dot org
On my locale machine here are the results :

$ locale -a | grep fr
fr_BE.utf8
fr_CA.utf8
fr_CH.utf8
fr_FR.utf8
fr_LU.utf8
$ php -f str.php
7.1.17-0ubuntu0.17.10.1 
in French Saturday andbool(false)

(i added echo phpversion() to your proposed script)
 [2018-06-23 22:08 UTC] jluc at no-log dot org
I tried also on various php online sandboxes :

WRONG :
https://wtools.io/php-sandbox ->  7.2.3 in French Saturday andbool(false)
http://sandbox.onlinephpfunctions.com/ -> 7.2.4 in French Saturday andbool(false)
https://3v4l.org/qfWTr-> 7.3.0alpha1 in French Saturday andbool(false)

RIGHT :
http://www.writephponline.com/-> 7.0.30 in French samedi andstring(5) "fr_FR"

If i understand well the issue is with setlocale's parameter.

Further tests on my local machine showed, i have to write setlocale("fr_FR.utf8"); 
This works. (instead of plain "fr_FR") 

This syntax is mentionned in some comments of https://secure.php.net/manual/fr/function.setlocale.php
but not in the official doc itself. 
Shouldnt that be explained ?

Is that a portable and safe way to go ?
 [2018-06-24 10:53 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-06-24 10:53 UTC] cmb@php.net
From the docs[1]:

| If locale is an array or followed by additional parameters then
| each array element or parameter is tried to be set as new locale
| until success. This is useful if a locale is known under different
| names on different systems or for providing a fallback for a
| possibly not available locale.

Also check the return value of setlocale() to see whether it
failed, and act appropriately.

[1] <http://php.net/manual/en/function.setlocale.php>
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Nov 19 11:01:25 2018 UTC