CodeIgniter Forums
How to translate month? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How to translate month? (/showthread.php?tid=79149)



How to translate month? - sfarzoso - 04-29-2021

I have this date 3/2021, and I'm trying to translate March into "Marzo", so I did:

PHP Code:
<?= DateTime::createFromFormat('m-Y'$d->date)->format(lang('date.month', ['F']) . '/Y'?>

locale file:

PHP Code:
<?php

$months 
= [
    'March' => 'Marzo'
];

return [
    'month' => "{0}"
]; 

how can I show "Marzo"?


RE: How to translate month? - wdeda - 04-29-2021

I use the example below, in a help, for the Portuguese:

PHP Code:
setlocale(LC_TIME'pt''portuguese');
    date_default_timezone_set('America/Sao_Paulo');

    //short date
    return utf8_encode(strftime('%d de %B'strtotime('today')));
    
    
//returns: 29 de abril
    
    
//long date
    return utf8_encode(strftime('%d de %B de %Y'strtotime('today')));
    
    
//returns 29 de abril de 2021