This topic is locked

Locale for dayname

11/17/2010 12:22:05 PM
PHPRunner General questions
A
Astrid author

I have the following code in Custom View as:

$value=date('D',strtotime($data["Datum"]));


But it returns English daynames and I need it to return Dutch daynames.

Is this possible?

Sergey Kornilov admin 11/17/2010

Astrid,
you need to change default locale in php.ini or in your code.
Try to add the following to AfterApplicationInitialized event:

setlocale (LC_ALL, 'nl_NL');



A few links that can help:

http://php.net/manual/en/function.setlocale.php

http://www.justskins.com/forums/i-want-the-date-5820.html

A
Astrid author 11/18/2010

Sergey,

Thx. But it doesn't work. First link you supplied is going nowhere, second gives no solution.

Found a solution by changing query into

DATE_FORMAT(Datum, '%w') AS Dag

so it returns the day number. Then I added this to the custom view properties:



$str = "";

if ($value=="0")

$str.="zo";

if ($value=="1")

$str.="ma";

if ($value=="2")

$str.="di";

if ($value=="3")

$str.="wo";

if ($value=="4")

$str.="do";

if ($value=="5")

$str.="vr";

if ($value=="6")

$str.="za";

$value=$str;


That's one problem solved. Except for the fact that I have 7 different views and have to add the code to everyone of them.
Now only having the same problem with a search list to find a specific month. Month headers are in English and so are month names in the list.

As this is not a field but a header I wonder if the same trick would work somehow. So instead of

DATE_FORMAT(Datum, '%M %Y') AS Maand



use

DATE_FORMAT(Datum, '%m %Y') AS Maand

to return the month number.

This is the code for the list now


$str = "";
$str.= "<select onchange=\"window.location.href=this.options[this.selectedIndex].
value;\"><option value=\"\">Kies maand</option>";
//select values from database
global $conn;
$strSQL = "SELECT DISTINCT DATE_FORMAT(Datum, '%m %Y') AS Maand FROM kalender group by Maand order by Datum ASC";
$rs = db_query($strSQL,$conn);
while ($data = db_fetch_array($rs))
$str.="<option value=\"kalender_list.php?a=search&value=1&SearchFor=".$row["header"]=$data["Maand"].
"&SearchOption=Contains&SearchField=Maand\">".$row["header"]=$data["Maand"]."</option>";
$str.="</select>";
echo $str;


Header and code are working ok. So only thing is to get rid of the English monthnames - numbers.

Sergey Kornilov admin 11/18/2010

Astrid,
I'm afraid you missing something. setlocale() function does exactly what you need affecting all PHP date/time functions like date() and strtotime()

A
Astrid author 11/19/2010

Sergey,

I must be missing something, but can't figure out what. As this was a 4.2 project that I converted to 5.2 I've set up a new test project in 5.2 to see if that whas the solution.

Simple table with some events and sql like

SELECT ID,

Datum,

Datum AS Dag

FROM kalender



Field Dag custom view

$value=date('D',strtotime($data["Datum"]));



Result (source code as I can't add a screen dump):

<td valign="middle" align="left">

<span id="edit4_Dag" >Thu</span>

</td>

<td valign="middle" align="left">

<span id="edit4_Datum" >2009-11-19</span>

</td>



After Appliciation initialized (from generated appsettings.php):

// here goes EVENT_INIT_APP event

setlocale (LC_ALL, 'nl_NL');
Sergey Kornilov admin 11/19/2010

'View as' format 'Custom' will be applied on List/View/Print pages only.
On the edit page I recommend to use one of date edit controls i.e. dropdown boxes with year, month, day. Also make sure you selected correct regional settings on Miscellaneous page in PHPRunner.

A
Astrid author 11/19/2010

Sergey,

The source code is from the list page. That's what I need it for. Used to have separate text fields in my database for "day" and "month year", but it complicates the input and seems silly to have 3 fields in a database with in fact the same data.
Miscellaneous page has Language Dutch (Standard) and Regional settings Nederlands (Nederland). Edit control on edit page for field "Datum" is dropdownboxes with datepicker.

Sergey Kornilov admin 11/19/2010

Astrid,
I'm a bit confused.
I recommend to post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

Sergey Kornilov admin 11/21/2010

The following works on Demo Account for abbreviated week day names.

setlocale(LC_ALL, 'nld_nld');

$value=strftime("%a",strtotime($data["Dag"]));