Last active
August 29, 2015 13:56
-
-
Save jeka-kiselyov/8791279 to your computer and use it in GitHub Desktop.
0F : Templates : Display Date in Different Languages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test date format:<br> | |
En: {234234|date_format:'%B %e, %Y'}<br> | |
Rus: {234234|date_format:'%e %m %Y':'':'rus'}<br> | |
Urk: {234234|date_format:'%e %m %Y':'':'ukr'}<br> | |
First parameter - php.net/strftime (%m is changed to 'января':'декабря' for Russian and 'ciчня':'грудня' for Ukrainian) | |
Second parameter - default date (if argument == '') | |
Third - 'auto', 'rus', 'ukr' | |
Works with 0F modified date_format Smarty plugin. It's below in this gist: modifier.date_format.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Put this to Smarty/plugins/modifier.date_format.php | |
*/ | |
function smarty_modifier_date_format($string, $format=null, $default_date='', $formatter='auto') | |
{ | |
if ($format === null) { | |
$format = Smarty::$_DATE_FORMAT; | |
} | |
/** | |
* Include the {@link shared.make_timestamp.php} plugin | |
*/ | |
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); | |
if ($string != '') { | |
$timestamp = smarty_make_timestamp($string); | |
} elseif ($default_date != '') { | |
$timestamp = smarty_make_timestamp($default_date); | |
} else { | |
return; | |
} | |
if($formatter=='rus') | |
{ | |
$months = array ( | |
1 => 'января', | |
2 => 'февраля', | |
3 => 'марта', | |
4 => 'апреля', | |
5 => 'мая', | |
6 => 'июня', | |
7 => 'июля', | |
8 => 'августа', | |
9 => 'сентября', | |
10 => 'октября', | |
11 => 'ноября', | |
12 => 'декабря'); | |
$format = str_replace("%m",$months[(int)date('m',$timestamp)],$format); | |
$formatter='auto'; | |
} elseif ($formatter =='ukr') | |
{ | |
$months = array ( | |
1 => 'січня', | |
2 => 'лютого', | |
3 => 'березня', | |
4 => 'квітня', | |
5 => 'травня', | |
6 => 'червня', | |
7 => 'липня', | |
8 => 'серпня', | |
9 => 'вересня', | |
10 => 'жовтня', | |
11 => 'листопада', | |
12 => 'грудня'); | |
$format = str_replace("%m",$months[(int)date('m',$timestamp)],$format); | |
$formatter='auto'; | |
} | |
if($formatter=='strftime' || ($formatter == 'auto' && strpos($format,'%') !== false)) | |
{ | |
if (DS == '\\') | |
{ | |
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); | |
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); | |
if (strpos($format, '%e') !== false) { | |
$_win_from[] = '%e'; | |
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); | |
} | |
if (strpos($format, '%l') !== false) { | |
$_win_from[] = '%l'; | |
$_win_to[] = sprintf('%\' 2d', date('h', $timestamp)); | |
} | |
$format = str_replace($_win_from, $_win_to, $format); | |
} | |
return strftime($format, $timestamp); | |
} else { | |
return date($format, $timestamp); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment