Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get translated monthNames/dayNames as array in Yii

Yii have a lot of translations in framework/i18n/data/%lang%.php files. Here are for example the german translations

I want to use Fullcalendar in my Yii project. To translate this Calendar, i must provide an array of monthNames/dayNames for current language. Fullcalendar monthNames Documentation

What is the best way in Yii to generate array like this:

['January', 'February', 'March', 'April', 'May', 'June', 'July',
 'August', 'September', 'October', 'November', 'December']
like image 294
TUNER88 Avatar asked Mar 13 '13 10:03

TUNER88


1 Answers

You can generate that with json_encode (or Yii native CJSON::encode()) and the data provided by Yii:

json_encode(
    include('path/to/yii/framework/i18n/data/de_de.php')['monthNames']['wide']
);

(This syntax required PHP 5.4 for array dereferencing)

From the current locale inside Yii that is:

json_encode(
    Yii::app()->locale->getMonthNames()
)

See http://www.yiiframework.com/doc/api/1.1/CLocale#getMonthNames-detail

like image 128
hakre Avatar answered Sep 19 '22 18:09

hakre