Search code examples
phpdatelocalizationlocale

setlocale and strftime not translating month


My code:

setlocale(LC_TIME, 'ca_ES');
echo strftime("%#d %B", strtotime($ticket->date_created));

outputs something like:

28 August

instead of my expectation:

28 Agost

I expect "Agost" because that is Catalan language (set through setlocale()).

Is this how setlocale and strftime is supposed to work?

FYI: My local development machine is Windows 7, set to locale: en-PH


Solution

  • The locale names are different on Windows. It looks like it's defaulting to English.

    Try the full length name (you can try several and it will pick the first found):

    setlocale(LC_TIME, 'ca_ES', 'Catalan_Spain', 'Catalan');
    

    You may look at this table, which may be helpful : http://docs.moodle.org/dev/Table_of_locales