Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to change default date language?
#9
PUBLISHED 19:25 / 13 poniedzia³ek, paŸdziernik, 2014

PHP Code:
<class="page-meta">Published &nbsp;<span><?php LOCAL_get_page_date('%H:%M / %e %A, %B, %Y'); ?></span></p>

<?php

setlocale
(LC_ALL'pl-PL'); // you should probably have this in your gsconfig.php

// here are the 3.4 functions ported for local use

/**
 * Get Page Date
 *
 * This will return the page's updated date/timestamp
 *
 * @since 1.0
 * @uses $date
 * @uses $TIMEZONE
 *
 * @param string $i Optional, default is "l, F jS, Y - g:i A"
 * @param bool $echo Optional, default is true. False will 'return' value
 * @return string Echos or returns based on param $echo
 */
function LOCAL_get_page_date($i "l, F jS, Y - g:i A"$echo=true) {
    global 
$TIMEZONE,$date;

    if (
$TIMEZONE != '') {
        if (
function_exists('date_default_timezone_set')) {
            
date_default_timezone_set($TIMEZONE);
        }
    }
    
    
$str LOCAL_formatDate($istrtotime($date));
    if(!
$echo) return $str;
    echo 
$str;
}

/**
 * Formated Date Output, special handling for params on windows
 *
 * @since  3.4
 * @author  cnb
 * 
 * @param  string $format    A strftime or date format
 * @param  time $timestamp   A timestamp
 * @return string            returns a formated date string
  */
function LOCAL_formatDate($format$timestamp null) {
    if(!
$timestamp$timestamp time();    

    if (
strpos($format'%') === false) {
        
$date date($format$timestamp);
    } 
    else {
        
$hostIsWindows = (strtoupper(substr(PHP_OS03)) === 'WIN');
        if (
$hostIsWindows) {
          
# fixes for Windows
          
$format preg_replace('#(?<!%)((?:%%)*)%e#''\1%#d'$format); // strftime %e parameter not supported
          
$date   utf8_encode(strftime($format$timestamp)); // strftime returns ISO-8859-1 encoded string
        
} else {
          
$date strftime($format$timestamp);
        }
     }
  
    return 
$date;
}

?>

strfttime does not support ordinal number suffixes, you would need to handle that on your own for your language.
1st, 2nd, 3rd

php 5.3 with PECL int supports i18n number formatting
PHP Code:
$nf = new NumberFormatter('en_US'NumberFormatter::ORDINAL);
print 
$nf->format(123); // prints 123rd 

This is all built into 3.4 already
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply


Messages In This Thread
How to change default date language? - by none20 - 2014-10-30, 03:31:37
RE: How to change default date language? - by shawn_a - 2014-10-30, 06:42:52



Users browsing this thread: 1 Guest(s)