modifier.localize_date.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
13 /**
14  * Date names to be included by l10n tools
15  * - $message->getText("Monday")
16  * - $message->getText("Tuesday")
17  * - $message->getText("Wednesday")
18  * - $message->getText("Thursday")
19  * - $message->getText("Friday")
20  * - $message->getText("Saturday")
21  * - $message->getText("Sunday")
22  * - $message->getText("January")
23  * - $message->getText("February")
24  * - $message->getText("March")
25  * - $message->getText("April")
26  * - $message->getText("May")
27  * - $message->getText("June")
28  * - $message->getText("July")
29  * - $message->getText("August")
30  * - $message->getText("September")
31  * - $message->getText("October")
32  * - $message->getText("November")
33  * - $message->getText("December")
34  */
35 
36 /**
37  * Localize the month and day names in a date string
38  *
39  * Example:
40  * @code
41  * {$date|date_format:"F Y"|localize_date:'de'}
42  * @endcode
43  *
44  * @param $date The date
45  * @param $lang The language
46  * @return String
47  */
48 function smarty_modifier_localize_date($date, $lang) {
49  // localize names
50  $message = ObjectFactory::getInstance('message');
51  $names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday",
52  "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
53  ];
54  foreach ($names as $name) {
55  $localizeName = $message->getText($name, null, $lang);
56  $localizeShortName = substr($localizeName, 0, 3);
57  $date = strtr($date, [$name => $localizeName, substr($name, 0, 3) => $localizeShortName]);
58  }
59  return $date;
60 }
61 ?>
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...