php - Change month name from other language to english in Smarty -


how change month name current locale (polish pl) english language in smarty?

i have this

 {$product->specificprice.to|date_format:'%d %b %y %h:%m:%s'} 

which gives me

 17 maj 2015 00:00:00 

"maj" in polish language means may , want have markup:

 17 may 2015 00:00:00 

you may want set locale time/date formats in php code :

    setlocale(lc_time, en_us.utf8); 

if want output dates in english in few places in templates , keep time/date locale polish, should write custom smarty modifier , use output dates in custom format.

not best simple way re-use smarty's date_format in custom modifier, following example shows (considering smarty 3):

    class smarty_extended extends smarty     {         private $_locale;          public function __construct($defaultlocale)         {             parent::__construct();              $this->_locale = $defaultlocale;             $this->loadplugin('smarty_modifier_date_format');             $this->registerplugin('modifier', 'date_format_eng', [$this, 'smarty_modifier_date_format_eng']);         }          public function smarty_modifier_date_format_eng($string, $format = null, $default_date = '', $formatter = 'auto')         {             setlocale(lc_time, 'en_us.utf8');             $date = smarty_modifier_date_format($string, $format, $default_date, $formatter);             setlocale(lc_time, $this->_locale);             return $date;         }     } 

now can use date_format_eng in template:

{$time|date_format_eng} may 22, 2015 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -