Search code examples
phpdatecakephpinternationalizationcakephp-3.x

how to display month names in russian in cakephp


I need to display month names in Russian, is it enough to change the defaultLocale value?

'defaultLocale' => env('APP_DEFAULT_LOCALE', 'ru_RU')

This doesnt seem to work, because <?= h($news->created->format('d F, Y')) ?> displays 01 October, 2016

Do I need to make changes anywhere else?


Solution

  • Changing the locale is enough in terms of configuration changes required, however in order to get localized output, you have to use the proper locale aware formatting methods, that is i18nFormat().

    It should be noted that this method uses ICU formatting patterns, not the standard PHP ones, see: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax

    So long story short, to get a localized variant of d F, Y, use

    $news->created->i18nFormat('dd MMMM, yyyy')
    

    For ru_RU this should return 01 октября, 2016.

    See also