GetSimple Support Forum
How to change default date language? - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: How to change default date language? (/showthread.php?tid=6887)



How to change default date language? - none20 - 2014-10-30

Hi folks!
I wanna change default date language, I already have Polish translation for GetSimple, but it's not containing the date.

For example:
I want to get a creation date on my page using code:
Code:
<?php get_page_date(); ?>

And it gives me:
Quote:Wednesday, October 29th, 2014 - 6:14 PM

Is somewhere Polish translation that includes also the "calendar / date " ?


RE: How to change default date language? - shawn_a - 2014-10-30

You can modify the date format that get_page_date uses, using date format flags as the first parameter.
But locales are not supported prior to 3.4 (development), so maybe you can use a more standard format at least.

carlos wrote a great function to handle this for 3.4, which we are still testing.
If you are interested in hacking in to your theme , let us know.

PHP Code:
/**
 * 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 get_page_date($i "l, F jS, Y - g:i A"$echo=true) { 



RE: How to change default date language? - none20 - 2014-10-30

Thank You for the replay.
And of course I am interested. What should I do with this code?


RE: How to change default date language? - shawn_a - 2014-10-30

nothing, that is the function as it exists in 3.3.x

you can change the argument to whatever you want say
get_page_date("F jS, Y - g:i A") for example

now if you know php , you can look at this function in the master branch on github and see how it uses the new formatDate() function that was created to use strftime instead of date()

or give us the format you want and maybe someone will write a function for you.


RE: How to change default date language? - none20 - 2014-10-30


Thank You, but my php is... none.
The structure I need is

6:14 / 29th Wednesday, October, 2014
hour / day, month, year

I dont know if I am clear enough - sorry for my English.


RE: How to change default date language? - shawn_a - 2014-10-30

and you want "wednesday,october"
in your language of choice assuming?

I honestly have no idea how that works, not sure if set_locale handles that.

hopefully someone else chimes in


RE: How to change default date language? - none20 - 2014-10-30

yes, which is Polish. I can provide You all these transition.


RE: How to change default date language? - hameau - 2014-10-30

(2014-10-30, 03:31:37)none20 Wrote:
Code:
<?php get_page_date(); ?>

You can do it with strftime function. If you change your snippet to this:
Code:
<?php echo strftime("%A, %e %B, %Y",get_page_date('U',false)); ?>

you will get the date according to the PHP locale set in gsconfig.php.

For example:
en_GB: Wednesday, 29 October, 2014
fr_FR: mercredi, 29 octobre, 2014

get_page_date('U',false) returns (instead of echo) the date in Unix epoch format, which is then changed to the locale-specific format by strftime.

See the PHP manual for strftime for all the formatting options.


RE: How to change default date language? - shawn_a - 2014-10-30

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


RE: How to change default date language? - hameau - 2014-10-30

(2014-10-30, 06:42:52)shawn_a Wrote: setlocale(LC_ALL, 'pl-PL');

In fact, you have to put
Code:
setlocale(LC_ALL, pl_PL.UTF-8);
to avoid the character encoding errors in Shawn's example.

pl_PL.UTF-8: środa, 29 październik, 2014
pl_PL: �roda, 29 pa�dziernik, 2014


RE: How to change default date language? - shawn_a - 2014-10-30

yeah but that all depends on your host, you need to know what your locales are , which is another issue entirely.
for example i am on windows, so i have no UTF locale support, and i have no idea why i have to use pl-PL instead of pl_PL

It looks like we will have add some iconv conversions to core for locales.
for example on windows
polish is available as Polish_Poland.1250
which can be handled via
echo iconv('windows-1250', 'UTF-8', strftime('%Y. %B %d. %A')) , "<br/>";
for example.
giving us
2014. październik 29. środa instead of
2014. paŸdziernik 29. œroda


RE: How to change default date language? - none20 - 2014-10-30

(2014-10-30, 06:20:35)hameau Wrote:
(2014-10-30, 03:31:37)none20 Wrote:
Code:
<?php get_page_date(); ?>

You can do it with strftime function. If you change your snippet to this:
Code:
<?php echo strftime("%A, %e %B, %Y",get_page_date('U',false)); ?>

you will get the date according to the PHP locale set in gsconfig.php.

For example:
en_GB: Wednesday, 29 October, 2014
fr_FR: mercredi, 29 octobre, 2014

get_page_date('U',false) returns (instead of echo) the date in Unix epoch format, which is then changed to the locale-specific format by strftime.

See the PHP manual for strftime for all the formatting options.


Yes !!! it works !!! You're amazing !!!
Simple easy - best : - )


RE: How to change default date language? - none20 - 2014-10-30

Both of You, thank You for helping me out.
I had to fix the line to:

setlocale(LC_ALL, 'pl_PL.UTF-8');
to make it work.

Now I have great website using Get-Simple : )