Show "Week Day" in localized language in the Time page for mobile

Discussion forum about Anuko Time Tracker
Post Reply
Semper
Posts: 17
Joined: Mon May 20, 2019 6:25 pm

Show "Week Day" in localized language in the Time page for mobile

Post by Semper » Mon May 27, 2019 6:37 pm

Hello.

In "WEB-INF/templates/mobile/time.tpl" I have changed:

Code: Select all

<td class="sectionHeaderNoBorder" align="center">{$timestring}</td>
to be:

Code: Select all

<td class="sectionHeaderNoBorder" align="center">{$timestring}&nbsp;{date("l", strtotime($timestring))}</td>
so that the weekday shows next to the numeric date in the Time pager for the mobile version. However, because I'm doing that in "raw" PHP, the weekday shows in plain English, whereas I would like it to show in the local language chosen for a given Group.

I know there is an array, "$i18n_weekdays", defined in "WEB-INF/resources/en.lang.php" (or the appropriate "XX.lang.php" file for the language at stake) which lets you customize the weekday names, but I don't know how to dinamically invoke the correct weekday name from that array as the displayed date changes in the Time pager for the mobile version.

Does anyone have any hints about how to accomplish that?

Semper
Posts: 17
Joined: Mon May 20, 2019 6:25 pm

Re: Show "Week Day" in localized language in the Time page for mobile

Post by Semper » Thu May 30, 2019 9:25 pm

Ok, so I managed for the Time page for mobile devices to show the WeekDay in Spanish.

I cheated, because I could not guess how to call the $i18n_weekdays array from "WEB-INF/resources/en.lang.php".

So I hard-coded the solution into the code of my installation of Time Tracker.

First, I edited "mobile/time.php" and added this line:

Code: Select all

setlocale(LC_TIME, 'es_ES.utf8');
Then, in "WEB-INF/templates/mobile/time.tpl" I modified my initial solution (which was displaying the WeekDay in English):

Code: Select all

<td class="sectionHeaderNoBorder" align="center">{$timestring}&nbsp;{date("l", strtotime($timestring))}</td>
so that it now is like this:

Code: Select all

<td class="sectionHeaderNoBorder" align="center">{$timestring}&nbsp;{strftime("%A", date("U", strtotime($timestring)))}</td>
This gives me want I wanted, although I am well aware that with this approach I am hard-coding the WeekDays in Spanish into the code. I would like to invoke the appropiate index number from the array $i18n_weekdays, but I don't know how to call that array.

ttuser
Posts: 5
Joined: Fri Mar 11, 2016 10:16 pm

Re: Show "Week Day" in localized language in the Time page for mobile

Post by ttuser » Fri May 31, 2019 12:24 pm

in mobile/time.php, you can use this to add properly localized day of week:

Code: Select all

$smarty->assign('timestring', $selected_date->toString($user->getDateFormat()).' '.$i18n->weekdayShortNames[$selected_date->getDay()]);

Semper
Posts: 17
Joined: Mon May 20, 2019 6:25 pm

Re: Show "Week Day" in localized language in the Time page for mobile

Post by Semper » Fri May 31, 2019 6:59 pm

ttuser wrote:
Fri May 31, 2019 12:24 pm
in mobile/time.php, you can use this to add properly localized day of week:

Code: Select all

$smarty->assign('timestring', $selected_date->toString($user->getDateFormat()).' '.$i18n->weekdayShortNames[$selected_date->getDay()]);
Thank you very much. That works!

So with that change as you say, I can get a properly localized "2019-05-31 Viernes" week day in the mobile version of the Time page, and also without any modification to "WEB-INF/templates/mobile/time.tpl", i.e, this code from original stock Time Tracker "WEB-INF/templates/mobile/time.tpl" produces the week day properly localized:

Code: Select all

<td class="sectionHeaderNoBorder" align="center">{$timestring}</td>

Post Reply