Localized Months

View: New views
2 Messages — Rating Filter:   Alert me  

Localized Months

by Justin Plock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Everyone,
  What would be the best way to get a listing of all of the months
localized to a given locale using Zend_Locale?  I've done this before:

// Build array of months
function build_months() {
   static $months = null;
   if (!isset($months)) {
     $months = array();
     for ($i = 1; $i <= 12; $i++) {
       $months[$i] = strftime('%B', mktime(12, 0, 0, $i, 1));
     }
   }
   return $months;
}

but that is dependent on using setlocale(), which I guess I could do as
well. Just looking to see what others have done.

Thanks.

-Justin


Re: Localized Months

by thomasW :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hy Justin,

one line of code is enough...

$months = new Zend_Locale()->getTranslationList('month', 'de');

just set the locale you want instead of 'de'
Or use the wished format as third parameter if you need abbreviated or
narrow months.

Greetings
Thomas Weidner, I18N Team Leader
http://www.thomasweidner.com


----- Original Message -----
From: "Justin Plock" <jplock@...>
To: <fw-i18n@...>
Sent: Wednesday, March 19, 2008 4:57 PM
Subject: [fw-i18n] Localized Months


> Hi Everyone,
>  What would be the best way to get a listing of all of the months
> localized to a given locale using Zend_Locale?  I've done this before:
>
> // Build array of months
> function build_months() {
>   static $months = null;
>   if (!isset($months)) {
>     $months = array();
>     for ($i = 1; $i <= 12; $i++) {
>       $months[$i] = strftime('%B', mktime(12, 0, 0, $i, 1));
>     }
>   }
>   return $months;
> }
>
> but that is dependent on using setlocale(), which I guess I could do as
> well. Just looking to see what others have done.
>
> Thanks.
>
> -Justin