Forums / Developer / Fetching a specific locale
Bruce Morrison
Wednesday 03 May 2006 7:06:54 pm
Howdy
I'm working on a multilingual site and have to produce a dropdown of Months as part of a form. This information is stored in a the locale but I'm having trouble retrieving the locale specific to the current siteaccess in an efficient way.
It appears that you can only retrieve the list of all locales using fetch( 'content', 'locale_list' ) and then loop through these until you find the correct one.
{def $localeName=ezini( 'RegionalSettings', 'Locale') $locales=fetch( 'content', 'locale_list' )} {foreach $locales as $l} {if eq($l.locale_full_code,$localeName)} {def $locale = $l} {break} {/if} {/foreach} {$locale|attribute(show,2)}
Is there a better way to do this (using 3.6)?
CheersBruce
My Blog: http://www.stuffandcontent.com/ Follow me on twitter: http://twitter.com/brucemorrison Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish
Łukasz Serwatka
Monday 08 May 2006 12:06:30 am
Hello,
Maybe this will help?
{def $ini_file=ezini('RegionalSettings', 'Locale')|append('.ini') $months=array( 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' )} {foreach $months as $month} {ezini('LongMonthNames', $month, $ini_file, 'share/locale', true)}<br /> {/foreach}
List of months fetched from locale file, will work for all siteaccess.
Personal website -> http://serwatka.net Blog (about eZ Publish) -> http://serwatka.net/blog
Valentin Doroschuk
Friday 08 September 2006 5:27:38 am
"Locale" fetch function: *SummaryFetches the available locale by locale code (for instance nor-NO or eng-GB.)
*Returnsezlocale object.
*Example
{def $current_locale = fetch( 'content', 'locale' ) $rus_ru_locale = fetch( 'content', 'locale', hash( 'locale_code', 'rus-RU' ) )} {$current_locale.locale_code} : {$current_locale.country_name} {$rus_ru_locale.locale_code} : {$rus_ru_locale.country_name}
Added to3.9.0alpha1 (trunk rev. 16839).