How to format a date to Brazilian Portuguese #1286
-
How to format a date to Brazilian Portuguese I'm trying this way {{ date(record.published_up).format('M d, Y') }}, but instead of the date appearing "Dez 05, 2024" it appears Dec 05, 2024. my config/app: my config/cms: |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 13 replies
-
Try this:
or this |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I made a Twig filter to achieve a date translation. Plugin.php use Session;
use Carbon\Carbon;
public function registerMarkupTags()
{
return [
'filters' => [
'translateDate' => [$this, 'translateDate'],
]
];
}
public function translateDate($date, $withYear = false)
{
if (!$date) return;
if (gettype($date) === 'string') $date = new Carbon($date);
$lang = Session::get('winter.translate.locale');
if ($withYear) return $date->locale($lang)->isoFormat('LL');
return $date->locale($lang)->isoFormat('D MMMM');
} file.htm
|
Beta Was this translation helpful? Give feedback.
-
@AIC-BV improved version: public function translateDate($date, $withYear = false)
{
if (!$date) return;
if (gettype($date) === 'string') $date = new Carbon($date);
$locale = Session::get('winter.translate.locale');
$format = $withYear ? 'LL' : (starts_with($locale, 'fr') ? 'D MMMM' : 'MMMM D');
return $date->locale($locale)->isoFormat($format);
} |
Beta Was this translation helpful? Give feedback.
-
Problem solved.
in Frontend: |
Beta Was this translation helpful? Give feedback.
Problem solved.
in plugin.php:
in Frontend:
<span><i class="fa fa-calendar"></i> {{ record.published_up | translateDate }}</span>