Carbon: setLocale only works in method diffForHumans

Created on 18 Oct 2016  路  13Comments  路  Source: briannesbitt/Carbon

Carbon::setLocale('pt_BR');
return Carbon::now()->format('l j F Y H:i:s');
It returns 'Monday 17 October 2016 21:53:33'
if I try with diffForHumans it works. What's wrong?
Is it a limitation or a bug?

Translate does not work for format

Most helpful comment

With Carbon 2.16 or newer:

Carbon::setLocale('pt_BR');

echo Carbon::now()->translatedFormat('l j F Y H:i:s');

All 13 comments

I've tried it, it does not work for "format".

Look at the first example.... formatLocalized()

$dt = Carbon::now();
setlocale(LC_TIME, 'German');
$dt->formatLocalized('%A %d %B %Y');

resulting in: Monday 17 October 2016

I don't know what to try anymore

Carbon::setLocale('pt_BR'); return Carbon::now('America/Fortaleza')->format('l j F Y H:i:s');// Monday 17 October 2016 22:12:38 (WRONG)

when:
`Carbon::setLocale('pt_BR');
return Carbon::now()->diffForHumans(); // h谩 1 segundo (RIGHT)

Get it?

Try this

setlocale(LC_TIME, "fr");
echo strftime("Weekday: %A");   // lundi

Doesn't rely on Carbon... but basically what Carbon is doing with the formatLocalized() call.

It did not work.
It did: 'Weekday: Monday'.
What is that about? Do you know?
So, it means that is not a Carbon problem, right?

Correct. Are you on linux?

on Linux
If you have trouble with translations, check locales installed in your system (local and production).
locale -a to list locales enabled.
sudo locale-gen fr_FR.UTF-8 to install a new locale.
sudo dpkg-reconfigure locales to publish all locale enabled.
And reboot your system.

This will depend on which flavour you are using, but you need to install the locale you want to use.

Dude, you saved my life!

I did this, the problem was in my linux was installed "pt_BR.utf8", no "pt_BR". Now, everything is working.

You were right, it's not a Carbon issue!

Thanks in advice, many thanks man!

馃憤

Cara, voc锚 salvou minha vida!

Eu fiz isso, o problema estava no meu linux foi instalado "pt_BR.utf8", n茫o "pt_BR". Agora tudo est谩 funcionando.

Voc锚 estava certo, n茫o 茅 uma quest茫o de carbono!

Obrigado em conselho, muito obrigado cara!

Bom Dia. O post 茅 antigo mas estou com o mesmo problema, como voce resolveu ?
Obs.: J谩 instalei o pt_BR.

With Carbon 2.16 or newer:

Carbon::setLocale('pt_BR');

echo Carbon::now()->translatedFormat('l j F Y H:i:s');

@kylekatarnls thanks, it works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrcnpdlk picture mrcnpdlk  路  4Comments

yica00 picture yica00  路  4Comments

joomartin picture joomartin  路  4Comments

ManojKiranA picture ManojKiranA  路  4Comments

JonoB picture JonoB  路  5Comments