TUNER88
TUNER88

Reputation: 923

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']

Upvotes: 5

Views: 3174

Answers (1)

hakre
hakre

Reputation: 198118

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

Upvotes: 6

Related Questions