| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.locale.functions">
- <title>Using Zend_Locale</title>
- <para>
- <classname>Zend_Locale</classname> also provides localized information about locales for each locale,
- including localized names for other locales, days of the week, month names, etc.
- </para>
- <sect2 id="zend.locale.copying">
- <title>Copying, Cloning, and Serializing Locale Objects</title>
- <para>
- Use
- <ulink url="http://php.net/language.oop5.cloning">object cloning</ulink>
- to duplicate a locale object exactly and efficiently. Most locale-aware methods also accept string
- representations of locales, such as the result of <code>$locale->toString()</code>.
- </para>
- <example id="zend.locale.copying.example-1">
- <title>clone</title>
- <programlisting language="php"><![CDATA[
- $locale = new Zend_Locale('ar');
- // Save the $locale object as a serialization
- $serializedLocale = $locale->serialize();
- // re-create the original object
- $localeObject = unserialize($serializedLocale);
- // Obtain a string identification of the locale
- $stringLocale = $locale->toString();
- // Make a cloned copy of the $local object
- $copiedLocale = clone $locale;
- print "copied: ", $copiedLocale->toString();
- // PHP automatically calls toString() via __toString()
- print "copied: ", $copiedLocale;
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.locale.equals">
- <title>Equality</title>
- <para>
- <classname>Zend_Locale</classname> also provides a convenience function to compare two locales. All locale-aware
- classes should provide a similar equality check.
- </para>
- <example id="zend.locale.equals.example-1">
- <title>Check for equal locales</title>
- <programlisting language="php"><![CDATA[
- $locale = new Zend_Locale();
- $mylocale = new Zend_Locale('en_US');
- // Check if locales are equal
- if ($locale->equals($mylocale)) {
- print "Locales are equal";
- }
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.locale.getdefault">
- <title>Default locales</title>
- <para>
- The method <methodname>getDefault()</methodname> returns an array of relevant locales using
- information from the user's web browser (if available), information from the
- environment of the host server, and Zend Framework settings. As with the constructor
- for <classname>Zend_Locale</classname>, the first parameter selects a preference of
- which information to consider <link
- linkend="zend.locale.selection">(<constant>BROWSER</constant>, <constant>ENVIRONMENT</constant>, or
- <code>FRAMEWORK)</code></link> first. The second parameter toggles between
- returning all matching locales or only the first/best match. Locale-aware components
- normally use only the first locale. A quality rating is included, when available.
- </para>
- <example id="zend.locale.getdefault.example-1">
- <title>Get default locales</title>
- <programlisting language="php"><![CDATA[
- $locale = new Zend_Locale();
- // Return all default locales
- $found = $locale->getDefault();
- print_r($found);
- // Return only browser locales
- $found2 = $locale->getDefault(Zend_Locale::BROWSER,TRUE);
- print_r($found2);
- ]]></programlisting>
- </example>
- <para>
- To obtain only the default locales relevant to the
- <link linkend="zend.locale.selection"><constant>BROWSER</constant>, <constant>ENVIRONMENT</constant>, or <constant>FRAMEWORK</constant>
- </link>
- , use the corresponding method:
- <itemizedlist>
- <listitem>
- <para>
- <methodname>getEnvironment()</methodname>
- </para>
- </listitem>
- <listitem>
- <para>
- <methodname>getBrowser()</methodname>
- </para>
- </listitem>
- <listitem>
- <para>
- <methodname>getLocale()</methodname>
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </sect2>
- <sect2 id="zend.locale.setlocale">
- <title>Set a new locale</title>
- <para>
- A new locale can be set with the function <methodname>setLocale()</methodname>. This function takes a locale string as
- parameter. If no locale is given, a locale is
- <link linkend="zend.locale.selection">automatically selected</link>.
- Since <classname>Zend_Locale</classname> objects are "light", this method exists primarily to cause side-effects for code that
- have references to the existing instance object.
- </para>
- <example id="zend.locale.setlocale.example-1">
- <title>setLocale</title>
- <programlisting language="php"><![CDATA[
- $locale = new Zend_Locale();
- // Actual locale
- print $locale->toString();
- // new locale
- $locale->setLocale('aa_DJ');
- print $locale->toString();
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.locale.getlocale">
- <title>Getting the language and region</title>
- <para>
- Use <methodname>getLanguage()</methodname> to obtain a string containing the two character language code from the string
- locale identifier. Use <methodname>getRegion()</methodname> to obtain a string containing the two character region code
- from the string locale identifier.
- </para>
- <example id="zend.locale.getlocale.example-1">
- <title>getLanguage and getRegion</title>
- <programlisting language="php"><![CDATA[
- $locale = new Zend_Locale();
- // if locale is 'de_AT' then 'de' will be returned as language
- print $locale->getLanguage();
- // if locale is 'de_AT' then 'AT' will be returned as region
- print $locale->getRegion();
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.locale.getdata">
- <title>Obtaining localized strings</title>
- <para>
- <methodname>getTranslationList()</methodname> gives you access to localized informations of several types. These
- information are useful if you want to display localized data to a customer without the need
- of translating it. They are already available for your usage.
- </para>
- <para>
- The requested list of information is always returned as named array. If you want to give more than
- one value to a explicit type where you wish to receive values from, you have to give an array
- instead of multiple values.
- </para>
- <example id="zend.locale.getdata.example-1">
- <title>getTranslationList</title>
- <programlisting language="php"><![CDATA[
- $list = Zend_Locale::getTranslationList('language', 'de_AT');
- print_r ($list);
- // example key -> value pairs...
- // [de] -> Deutsch
- // [en] -> Englisch
- // use one of the returned key as value for the getTranslation() method
- // of another language
- print Zend_Locale::getTranslation('de', 'language', 'zh');
- // returns the translation for the language 'de' in chinese
- ]]></programlisting>
- </example>
- <para>
- You can receive this informations for all languages. But not all of the informations are completely
- available for all languages. Some of these types are also available through an own function for
- simplicity. See this list for detailed informations.
- </para>
- <table id="zend.locale.getdata.table-1">
- <title>Details for getTranslationList($type = null, $locale = null, $value = null)</title>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>Type</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry><emphasis>Language</emphasis></entry>
- <entry>Returns a localized list of all languages. The language part of the locale
- is returned as key and the translation as value</entry>
- </row>
- <row>
- <entry><emphasis>Script</emphasis></entry>
- <entry>Returns a localized list of all scripts. The script is returned as key and the
- translation as value</entry>
- </row>
- <row>
- <entry><emphasis>Territory</emphasis></entry>
- <entry>Returns a localized list of all territories. This contains countries,
- continents and territories. To get only territories and continents
- use '1' as value. To get only countries use '2' as value. The country part of
- the locale is used as key where applicable. In the other case the official <acronym>ISO</acronym>
- code for this territory is used. The translated territory is returned as value.
- When you omit the value you will get a list with both.</entry>
- </row>
- <row>
- <entry><emphasis>Variant</emphasis></entry>
- <entry>Returns a localized list of known variants of scripts. The variant is
- returned as key and the translation as value</entry>
- </row>
- <row>
- <entry><emphasis>Key</emphasis></entry>
- <entry>Returns a localized list of known keys. This keys are generic values used
- in translation. These are normally calendar, collation and currency. The key
- is returned as array key and the translation as value</entry>
- </row>
- <row>
- <entry><emphasis>Type</emphasis></entry>
- <entry>Returns a localized list of known types of keys. These are variants of types
- of calendar representations and types of collations. When you use 'collation' as
- value you will get all types of collations returned. When you use 'calendar' as
- value you will get all types of calendars returned. When you omit the value you
- will get a list all both returned. The type is used as key and the translation as
- value</entry>
- </row>
- <row>
- <entry><emphasis>Layout</emphasis></entry>
- <entry>Returns a list of rules which describes how to format special text parts</entry>
- </row>
- <row>
- <entry><emphasis>Characters</emphasis></entry>
- <entry>Returns a list of allowed characters within this locale</entry>
- </row>
- <row>
- <entry><emphasis>Delimiters</emphasis></entry>
- <entry>Returns a list of allowed quoting characters for this locale</entry>
- </row>
- <row>
- <entry><emphasis>Measurement</emphasis></entry>
- <entry>Returns a list of known measurement values. This list is depreciated</entry>
- </row>
- <row>
- <entry><emphasis>Months</emphasis></entry>
- <entry>Returns a list of all month representations within this locale. There are
- several different representations which are all returned as sub array. If you omit
- the value you will get a list of all months from the 'gregorian' calendar returned.
- You can give any known calendar as value to get a list of months from this calendar
- returned. Use <link linkend="zend.date.introduction">Zend_Date</link> for
- simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Month</emphasis></entry>
- <entry>Returns a localized list of all month names for this locale. If you omit the
- value you will get the normally used gregorian full name of the months where each
- month number is used as key and the translated month is returned as value. You
- can get the months for different calendars and formats if you give an array as value.
- The first array entry has to be the calendar, the second the used context and the
- third the width to return. Use <link linkend="zend.date.introduction">Zend_Date</link>
- for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Days</emphasis></entry>
- <entry>Returns a list of all day representations within this locale. There are
- several different representations which are all returned as sub array. If you omit
- the value you will get a list of all days from the 'gregorian' calendar returned.
- You can give any known calendar as value to get a list of days from this calendar
- returned. Use <link linkend="zend.date.introduction">Zend_Date</link> for
- simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Day</emphasis></entry>
- <entry>Returns a localized list of all day names for this locale. If you omit the
- value you will get the normally used gregorian full name of the days where the
- english day abbreviation is used as key and the translated day is returned as
- value. You can get the days for different calendars and formats if you give an
- array as value. The first array entry has to be the calendar, the second the used
- context and the third the width to return. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Week</emphasis></entry>
- <entry>Returns a list of values used for proper week calculations within a locale.
- Use <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Quarters</emphasis></entry>
- <entry>Returns a list of all quarter representations within this locale. There are
- several different representations which are all returned as sub array. If you omit
- the value you will get a list of all quarters from the 'gregorian' calendar returned.
- You can give any known calendar as value to get a list of quarters from this calendar
- returned</entry>
- </row>
- <row>
- <entry><emphasis>Quarter</emphasis></entry>
- <entry>Returns a localized list of all quarter names for this locale. If you omit the
- value you will get the normally used gregorian full name of the quarters where each
- quarter number is used as key and the translated quarter is returned as value. You
- can get the quarters for different calendars and formats if you give an array as
- value. The first array entry has to be the calendar, the second the used context
- and the third the width to return</entry>
- </row>
- <row>
- <entry><emphasis>Eras</emphasis></entry>
- <entry>Returns a list of all era representations within this locale. If you omit
- the value you will get a list of all eras from the 'gregorian' calendar returned.
- You can give any known calendar as value to get a list of eras from this calendar
- returned</entry>
- </row>
- <row>
- <entry><emphasis>Era</emphasis></entry>
- <entry>Returns a localized list of all era names for this locale. If you omit the
- value you will get the normally used gregorian full name of the eras where each
- era number is used as key and the translated era is returned as value. You
- can get the eras for different calendars and formats if you give an array as
- value. The first array entry has to be the calendar and the second the width to
- return</entry>
- </row>
- <row>
- <entry><emphasis>Date</emphasis></entry>
- <entry>Returns a localized list of all date formats for this locale. The name of the
- dateformat is used as key and the format itself as value.If you omit the value you
- will get the date formats for the gregorian calendar returned. You can get the
- date formats for different calendars if you give the wished calendar as string.
- Use <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Time</emphasis></entry>
- <entry>Returns a localized list of all time formats for this locale. The name of the
- timeformat is used as key and the format itself as value. If you omit the value you
- will get the time formats for the gregorian calendar returned. You can get the
- time formats for different calendars if you give the wished calendar as string.
- Use <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DateTime</emphasis></entry>
- <entry>Returns a localized list of all known date-time formats for this locale. The name
- of the date-time format is used as key and the format itself as value. If you
- omit the value you will get the date-time formats for the gregorian calendar returned.
- You can get the date-time formats for different calendars if you give the wished
- calendar as string. Use <link linkend="zend.date.introduction">Zend_Date</link>
- for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DateItem</emphasis></entry>
- <entry>Returns a list of default formats for given date or time items</entry>
- </row>
- <row>
- <entry><emphasis>DateInterval</emphasis></entry>
- <entry>
- Returns a list of date or time formats which are used when you want to
- display intervals. The list is a multidimentional array where the first
- dimension is the interval format, and the second dimension is the token
- with the greatest difference.
- </entry>
- </row>
- <row>
- <entry><emphasis>Field</emphasis></entry>
- <entry>Returns a localized list of date fields which can be used to display calendars
- or date strings like 'month' or 'year' in a wished language. If you omit the value
- you will get this list for the gregorian calendar returned. You can get the
- list for different calendars if you give the wished calendar as string</entry>
- </row>
- <row>
- <entry><emphasis>Relative</emphasis></entry>
- <entry>Returns a localized list of relative dates which can be used to display
- textual relative dates like 'yesterday' or 'tomorrow' in a wished language.
- If you omit the value you will get this list for the gregorian calendar
- returned. You can get the list for different calendars if you give the wished
- calendar as string</entry>
- </row>
- <row>
- <entry><emphasis>Symbols</emphasis></entry>
- <entry>Returns a localized list of characters used for number representations</entry>
- </row>
- <row>
- <entry><emphasis>NameToCurrency</emphasis></entry>
- <entry>Returns a localized list of names for currencies. The currency is used as key
- and the translated name as value. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyToName</emphasis></entry>
- <entry>Returns a list of currencies for localized names. The translated name is used
- as key and the currency as value. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencySymbol</emphasis></entry>
- <entry>Returns a list of known localized currency symbols for currencies. The
- currency is used as key and the symbol as value. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Question</emphasis></entry>
- <entry>Returns a list of localized strings for acceptance ('yes') and
- negotation ('no'). Use
- <link linkend="zend.locale.getquestion">Zend_Locale's getQuestion method</link>
- for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyFraction</emphasis></entry>
- <entry>Returns a list of fractions for currency values. The currency is used as key and
- the fraction as integer value. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyRounding</emphasis></entry>
- <entry>Returns a list of how to round which currency. The currency is used as key and
- the rounding as integer value. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyToRegion</emphasis></entry>
- <entry>Returns a list of currencies which are known to be used within a region.
- The <constant>ISO3166</constant> value ('region') is used as array key and the <constant>ISO4217</constant> value
- ('currency') as array value. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>RegionToCurrency</emphasis></entry>
- <entry>Returns a list of regions where a currency is used . The <constant>ISO4217</constant> value ('currency')
- is used as array key and the <constant>ISO3166</constant> value ('region') as array value. When a currency
- is used in several regions these regions are separated with a whitespace. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>RegionToTerritory</emphasis></entry>
- <entry>Returns a list of territories with the countries or sub territories which are
- included within that territory. The <acronym>ISO</acronym> territory code ('territory') is used as
- array key and the <constant>ISO3166</constant> value ('region') as array value. When a territory contains
- several regions these regions are separated with a whitespace</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToRegion</emphasis></entry>
- <entry>Returns a list of regions and the territories where these regions are located.
- The <constant>ISO3166</constant> code ('region') is used as array key and the <acronym>ISO</acronym> territory code
- ('territory') as array value. When a region is located in several territories
- these territories are separated with a whitespace</entry>
- </row>
- <row>
- <entry><emphasis>ScriptToLanguage</emphasis></entry>
- <entry>Returns a list of scripts which are used within a language. The language code
- is used as array key and the script code as array value. When a language contains
- several scripts these scripts are separated with a whitespace</entry>
- </row>
- <row>
- <entry><emphasis>LanguageToScript</emphasis></entry>
- <entry>Returns a list of languages which are using a script. The script code
- is used as array key and the language code as array value. When a script is used
- in several languages these languages are separated with a whitespace</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToLanguage</emphasis></entry>
- <entry>Returns a list of countries which are using a language. The country code
- is used as array key and the language code as array value. When a language is used in
- several countries these countries are separated with a whitespace</entry>
- </row>
- <row>
- <entry><emphasis>LanguageToTerritory</emphasis></entry>
- <entry>Returns a list of countries and the languages spoken within these countries.
- The country code is used as array key and the language code as array value. When
- a territory is using several languages these languages are separated with a
- whitespace</entry>
- </row>
- <row>
- <entry><emphasis>TimezoneToWindows</emphasis></entry>
- <entry>Returns a list of windows timezones and the related <acronym>ISO</acronym> timezone. The windows
- timezone is used as array key and the <acronym>ISO</acronym> timezone as array value</entry>
- </row>
- <row>
- <entry><emphasis>WindowsToTimezone</emphasis></entry>
- <entry>Returns a list of <acronym>ISO</acronym> timezones and the related windows timezone. The <acronym>ISO</acronym>
- timezone is used as array key and the windows timezone as array value</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToTimezone</emphasis></entry>
- <entry>Returns a list of regions or territories and the related <acronym>ISO</acronym> timezone. The
- <acronym>ISO</acronym> timezone is used as array key and the territory code as array value</entry>
- </row>
- <row>
- <entry><emphasis>TimezoneToTerritory</emphasis></entry>
- <entry>Returns a list of timezones and the related region or territory code. The
- region or territory code is used as array key and the <acronym>ISO</acronym> timezone as array
- value</entry>
- </row>
- <row>
- <entry><emphasis>CityToTimezone</emphasis></entry>
- <entry>Returns a localized list of cities which can be used as translation for a
- related timezone. Not for all timezones is a translation available, but for a
- user is the real city written in his languages more accurate than the <acronym>ISO</acronym> name
- of this timezone. The <acronym>ISO</acronym> timezone is used as array key and the translated
- city as array value</entry>
- </row>
- <row>
- <entry><emphasis>TimezoneToCity</emphasis></entry>
- <entry>Returns a list of timezones for localized city names. The localized city is
- used as array key and the <acronym>ISO</acronym> timezone name as array value</entry>
- </row>
- <row>
- <entry><emphasis>PhoneToTerritory</emphasis></entry>
- <entry>Returns a list of phone codes which are known to be used within a territory.
- The territory (region) is used as array key and the telephone code
- as array value</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToPhone</emphasis></entry>
- <entry>Returns a list of territories where a phone is used . The phone code
- is used as array key and the territory (region) as array value. When a
- phone code is used in several territories these territories are separated with a
- whitespace</entry>
- </row>
- <row>
- <entry><emphasis>NumericToTerritory</emphasis></entry>
- <entry>Returns a list of 3 digit number codes for territories.
- The territory (region) is used as array key and the 3 digit number code
- as array value</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToNumeric</emphasis></entry>
- <entry>Returns a list of territories with their 3 digit number code. The 3 digit
- number code is used as array key and the territory (region) as array value
- </entry>
- </row>
- <row>
- <entry><emphasis>Alpha3ToTerritory</emphasis></entry>
- <entry>Returns a list of 3 sign character codes for territories.
- The territory (region) is used as array key and the 3 sign character code
- as array value</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToAlpha3</emphasis></entry>
- <entry>Returns a list of territories with their 3 sign character code. The 3 sign
- character code is used as array key and the territory (region) as array value
- </entry>
- </row>
- <row>
- <entry><emphasis>PostalToTerritory</emphasis></entry>
- <entry>Returns a list of territories with a regex for postal codes which are
- included within that territory. The <acronym>ISO</acronym> territory code ('territory') is used as
- array key and the regex as array value.</entry>
- </row>
- <row>
- <entry><emphasis>NumberingSystem</emphasis></entry>
- <entry>
- Returns a list of scripts with the notation for digits used within the
- script
- </entry>
- </row>
- <row>
- <entry><emphasis>FallbackToChar</emphasis></entry>
- <entry>
- Returns a list of replacement characters for often used unicode characters.
- This can be used to replace "©" with "(C)" for example
- </entry>
- </row>
- <row>
- <entry><emphasis>CharToFallback</emphasis></entry>
- <entry>
- Returns a list of unicode characters for often used replacement characters.
- This can be used to replace "(C)" with "©" for example
- </entry>
- </row>
- <row>
- <entry><emphasis>LocaleUpgrade</emphasis></entry>
- <entry>
- Returns a list of locale dependencies which can be used to upgrade a
- language to a full qualified locale
- </entry>
- </row>
- <row>
- <entry><emphasis>Unit</emphasis></entry>
- <entry>
- Returns a list of localized calendar units. This can be used to translate
- the strings "day", "month" and so on automatically
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>
- If you are in need of a single translated value, you can use the <methodname>getTranslation()</methodname>
- method. It returns always a string but it accepts some different types than the
- <methodname>getTranslationList()</methodname> method. Also value is the same as before with one difference.
- You have to give the detail you want to get returned as additional value.
- </para>
- <note>
- <para>
- Because you have almost always give a value as detail this parameter has to be given
- as first parameter. This differs from the <methodname>getTranslationList()</methodname> method.
- </para>
- </note>
- <para>
- See the following table for detailed information:
- </para>
- <table id="zend.locale.getdata.table-2">
- <title>Details for getTranslation($value = null, $type = null, $locale = null)</title>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>Type</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry><emphasis>Language</emphasis></entry>
- <entry>Returns a translation for a language. To select the wished translation
- you must give the language code as value</entry>
- </row>
- <row>
- <entry><emphasis>Script</emphasis></entry>
- <entry>Returns a translation for a script. To select the wished translation you
- must give the script code as value</entry>
- </row>
- <row>
- <entry><emphasis>Territory</emphasis> or
- <emphasis>Country</emphasis></entry>
- <entry>Returns a translation for a territory. This can be countries, continents
- and territories. To select the wished variant you must give the territory
- code as value</entry>
- </row>
- <row>
- <entry><emphasis>Variant</emphasis></entry>
- <entry>Returns a translation for a script variant. To select the wished variant
- you must give the variant code as value</entry>
- </row>
- <row>
- <entry><emphasis>Key</emphasis></entry>
- <entry>Returns translation for a known keys. This keys are generic values used
- in translation. These are normally calendar, collation and currency. To
- select the wished key you must give the key code as value</entry>
- </row>
- <row>
- <entry><emphasis>DefaultCalendar</emphasis></entry>
- <entry>Returns the default calendar for the given locale. For most locales this
- will be 'gregorian'. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>MonthContext</emphasis></entry>
- <entry>Returns the default context for months which is used within the given
- calendar. If you omit the value the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DefaultMonth</emphasis></entry>
- <entry>Returns the default format for months which is used within the given
- calendar. If you omit the value the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Month</emphasis></entry>
- <entry>Returns a translation for a month. You have to give the number of the month
- as integer value. It has to be between 1 and 12. If you want to receive data for
- other calendars, contexts or formats, then you must give an array instead of an
- integer with the expected values. The array has to look like this: <code>array(
- 'calendar', 'context', 'format', 'month number')</code>. If you give only an
- integer then the default values are the 'gregorian' calendar, the context
- 'format' and the format 'wide'. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DayContext</emphasis></entry>
- <entry>Returns the default context for ´days which is used within the given
- calendar. If you omit the value the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DefaultDay</emphasis></entry>
- <entry>Returns the default format for days which is used within the given
- calendar. If you omit the value the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Day</emphasis></entry>
- <entry>Returns a translation for a day. You have to give the english abbreviation
- of the day as string value ('sun', 'mon', etc.). If you want to receive data
- for other calendars, contexts or format, then you must give an array instead of
- an integer with the expected values. The array has to look like this:
- <methodname>array('calendar', 'context', 'format', 'day abbreviation')</methodname>. If you
- give only an string then the default values are the 'gregorian' calendar,
- the context 'format' and the format 'wide'. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Quarter</emphasis></entry>
- <entry>Returns a translation for a quarter. You have to give the number of the
- quarter as integer and it has to be between 1 and 4. If you want to receive
- data for other calendars, contexts or formats, then you must give an array
- instead of an integer with the expected values. The array has to look like this:
- <methodname>array('calendar', 'context', 'format', 'quarter number')</methodname>. If you
- give only an string then the default values are the 'gregorian' calendar,
- the context 'format' and the format 'wide'</entry>
- </row>
- <row>
- <entry><emphasis>Am</emphasis></entry>
- <entry>Returns a translation for 'AM' in a expected locale. If you want to receive
- data for other calendars an string with the expected calendar. If you omit the
- value then the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Pm</emphasis></entry>
- <entry>Returns a translation for 'PM' in a expected locale. If you want to receive
- data for other calendars an string with the expected calendar. If you omit the
- value then the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Era</emphasis></entry>
- <entry>Returns a translation for an era within a locale. You have to give the era
- number as string or integer. If you want to receive data for other calendars or
- formats, then you must give an array instead of the era number with the expected
- values. The array has to look like this:
- <methodname>array('calendar', 'format', 'era number')</methodname>. If you give only an
- string then the default values are the 'gregorian' calendar and the 'abbr'
- format</entry>
- </row>
- <row>
- <entry><emphasis>DefaultDate</emphasis></entry>
- <entry>Returns the default date format which is used within the given
- calendar. If you omit the value the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Date</emphasis></entry>
- <entry>Returns the date format for an given calendar or format within a locale.
- If you omit the value then the 'gregorian' calendar will be used with the
- 'medium' format. If you give a string then the 'gregorian' calendar will be
- used with the given format. Or you can also give an array which will have to
- look like this: <methodname>array('calendar', 'format')</methodname>. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DefaultTime</emphasis></entry>
- <entry>Returns the default time format which is used within the given
- calendar. If you omit the value the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Time</emphasis></entry>
- <entry>Returns the time format for an given calendar or format within a locale.
- If you omit the value then the 'gregorian' calendar will be used with the
- 'medium' format. If you give a string then the 'gregorian' calendar will be
- used with the given format. Or you can also give an array which will have to
- look like this: <methodname>array('calendar', 'format')</methodname>. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DateTime</emphasis></entry>
- <entry>Returns the datetime format for the given locale which indicates how to
- display date with times in the same string within the given calendar. If you
- omit the value the 'gregorian' calendar will be used. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DateItem</emphasis></entry>
- <entry>Returns the default format for a given date or time item</entry>
- </row>
- <row>
- <entry><emphasis>DateInterval</emphasis></entry>
- <entry>
- Returns the interval format for a given date or time format. The first
- value is the calendar format, normally 'gregorian'. The second value is
- the interval format and the third value the token with the greatest
- difference. For example: array('gregorian', 'yMMMM', 'y') returns the
- interval format for the date format 'yMMMM' where 'y' has the greatest
- difference.
- </entry>
- </row>
- <row>
- <entry><emphasis>Field</emphasis></entry>
- <entry>Returns a translated date field which can be used to display calendars or
- date strings like 'month' or 'year' in a wished language. You must give the
- field which has to be returned as string. In this case the 'gregorian'
- calendar will be used. You can get the field for other calendar formats if you
- give an array which has to look like this:
- <methodname>array('calendar', 'date field')</methodname></entry>
- </row>
- <row>
- <entry><emphasis>Relative</emphasis></entry>
- <entry>Returns a translated date which is relative to today which can include date
- strings like 'yesterday' or 'tomorrow' in a wished language. You have to give
- the number of days relative to tomorrow to receive the expected string. Yesterday
- would be '-1', tomorrow '1' and so on. This will use the 'gregorian' calendar. If
- you want to get relative dates for other calendars you will have to give an array
- which has to look like this: <methodname>array('calendar', 'relative days')</methodname>. Use
- <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>DecimalNumber</emphasis></entry>
- <entry>Returns the format for decimal numbers within a given locale. Use
- <link linkend="zend.locale.parsing">Zend_Locale_Format</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>ScientificNumber</emphasis></entry>
- <entry>Returns the format for scientific numbers within a given locale</entry>
- </row>
- <row>
- <entry><emphasis>PercentNumber</emphasis></entry>
- <entry>Returns the format for percentage numbers within a given locale</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyNumber</emphasis></entry>
- <entry>Returns the format for displaying currency numbers within a given locale. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>NameToCurrency</emphasis></entry>
- <entry>Returns the translated name for a given currency. The currency has to be
- given in <acronym>ISO</acronym> format which is for example 'EUR' for the currency 'euro'. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyToName</emphasis></entry>
- <entry>Returns a currency for a given localized name. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencySymbol</emphasis></entry>
- <entry>Returns the used symbol for a currency within a given locale. Not for all
- currencies exists a symbol. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>Question</emphasis></entry>
- <entry>Returns a localized string for acceptance ('yes') and
- negotation ('no'). You have to give either 'yes' or 'no' as value to receive the
- expected string. Use
- <link linkend="zend.locale.getquestion">Zend_Locale's getQuestion method</link>
- for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyFraction</emphasis></entry>
- <entry>Returns the fraction to use for a given currency. You must give the currency
- as <acronym>ISO</acronym> value. Use <link linkend="zend.currency.introduction">Zend_Currency</link>
- for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyRounding</emphasis></entry>
- <entry>Returns how to round a given currency. You must give the currency
- as <acronym>ISO</acronym> value. If you omit the currency then the 'DEFAULT' rounding will be
- returned. Use <link linkend="zend.currency.introduction">Zend_Currency</link>
- for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>CurrencyToRegion</emphasis></entry>
- <entry>Returns the currency for a given region. The region code has to be given
- as <constant>ISO3166</constant> string for example 'AT' for austria. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>RegionToCurrency</emphasis></entry>
- <entry>Returns the regions where a currency is used. The currency has to be given
- as <constant>ISO4217</constant> code for example 'EUR' for euro. When a currency is used in multiple
- regions, these regions are separated with a whitespace character. Use
- <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
- </row>
- <row>
- <entry><emphasis>RegionToTerritory</emphasis></entry>
- <entry>Returns the regions for a given territory. The territory has to be given as
- <constant>ISO4217</constant> string for example '001' for world. The regions within this territory
- are separated with a whitespace character</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToRegion</emphasis></entry>
- <entry>Returns the territories where a given region is located. The region has to be
- given in <constant>ISO3166</constant> string for example 'AT' for austria. When a region is located in
- multiple territories then these territories are separated with a whitespace
- character</entry>
- </row>
- <row>
- <entry><emphasis>ScriptToLanguage</emphasis></entry>
- <entry>Returns the scripts which are used within a given language. The language has
- to be given as <acronym>ISO</acronym> language code for example 'en' for english. When multiple
- scripts are used within a language then these scripts are separated with a
- whitespace character</entry>
- </row>
- <row>
- <entry><emphasis>LanguageToScript</emphasis></entry>
- <entry>Returns the languages which are used within a given script. The script has to be
- given as <acronym>ISO</acronym> script code for example 'Latn' for latin. When a script is used in
- multiple languages then these languages are separated with a whitespace
- character</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToLanguage</emphasis></entry>
- <entry>Returns the territories where a given language is used. The language has
- to be given as <acronym>ISO</acronym> language code for example 'en' for english. When multiple
- territories exist where this language is used then these territories are
- separated with a whitespace character</entry>
- </row>
- <row>
- <entry><emphasis>LanguageToTerritory</emphasis></entry>
- <entry>Returns the languages which are used within a given territory. The territory
- has to be given as <constant>ISO3166</constant> code for example 'IT' for italia. When a language
- is used in multiple territories then these territories are separated with a
- whitespace character</entry>
- </row>
- <row>
- <entry><emphasis>TimezoneToWindows</emphasis></entry>
- <entry>Returns a <acronym>ISO</acronym> timezone for a given windows timezone</entry>
- </row>
- <row>
- <entry><emphasis>WindowsToTimezone</emphasis></entry>
- <entry>Returns a windows timezone for a given <acronym>ISO</acronym> timezone</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToTimezone</emphasis></entry>
- <entry>Returns the territory for a given <acronym>ISO</acronym> timezone</entry>
- </row>
- <row>
- <entry><emphasis>TimezoneToTerritory</emphasis></entry>
- <entry>Returns the <acronym>ISO</acronym> timezone for a given territory</entry>
- </row>
- <row>
- <entry><emphasis>CityToTimezone</emphasis></entry>
- <entry>Returns the localized city for a given <acronym>ISO</acronym> timezone. Not for all timezones
- does a city translation exist</entry>
- </row>
- <row>
- <entry><emphasis>TimezoneToCity</emphasis></entry>
- <entry>Returns the <acronym>ISO</acronym> timezone for a given localized city name. Not for all cities
- does a timezone exist</entry>
- </row>
- <row>
- <entry><emphasis>PhoneToTerritory</emphasis></entry>
- <entry>Returns the telephone code for a given territory (region). The territory code
- has to be given as <constant>ISO3166</constant> string for example 'AT' for austria</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToPhone</emphasis></entry>
- <entry>Returns the territory (region) where a telephone code is used. The telephone
- code has to be given as plain integer code for example '43' for +43. When a
- telephone code is used in multiple territories (regions), these territories are
- separated with a whitespace character</entry>
- </row>
- <row>
- <entry><emphasis>NumericToTerritory</emphasis></entry>
- <entry>Returns the 3 digit number code for a given territory (region). The territory
- code has to be given as <constant>ISO3166</constant> string for example 'AT' for austria</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToNumeric</emphasis></entry>
- <entry>Returns the territory (region) for a 3 digit number code. The 3 digit number
- code has to be given as plain integer code for example '43'
- </entry>
- </row>
- <row>
- <entry><emphasis>Alpha3ToTerritory</emphasis></entry>
- <entry>Returns the 3 sign character code for a given territory (region). The territory
- code has to be given as <constant>ISO3166</constant> string for example 'AT' for austria</entry>
- </row>
- <row>
- <entry><emphasis>TerritoryToAlpha3</emphasis></entry>
- <entry>Returns the territory (region) for a 3 sign character code</entry>
- </row>
- <row>
- <entry><emphasis>PostalToTerritory</emphasis></entry>
- <entry>
- Returns the a regex for postal codes for a given territory. The
- territory has to be given as <constant>ISO4217</constant> string for example '001' for
- world</entry>
- </row>
- <row>
- <entry><emphasis>NumberingSystem</emphasis></entry>
- <entry>
- Returns a scripts with the notation for digits used within this script
- </entry>
- </row>
- <row>
- <entry><emphasis>FallbackToChar</emphasis></entry>
- <entry>
- Returns a replacement character for a often used unicode character.
- This can be used to replace "©" with "(C)" for example
- </entry>
- </row>
- <row>
- <entry><emphasis>CharToFallback</emphasis></entry>
- <entry>
- Returns a unicode character for a often used replacement character.
- This can be used to replace "(C)" with "©" for example
- </entry>
- </row>
- <row>
- <entry><emphasis>LocaleUpgrade</emphasis></entry>
- <entry>
- Returns a locale dependencies for a given language which can be used to
- upgrade this language to a full qualified locale
- </entry>
- </row>
- <row>
- <entry><emphasis>Unit</emphasis></entry>
- <entry>
- Returns a localized calendar unit. This can be used to translate
- the strings "day", "month" and so on automatically. The first parameter
- has to be the type, and the second parameter has to be the count
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <note>
- <para>
- With Zend Framework 1.5 several old types have been renamed. This has to be done because
- of several new types, some misspelling and to increase the usability. See this table for
- a list of old to new types:
- </para>
- </note>
- <table id="zend.locale.getdata.table-3">
- <title>Differences between Zend Framework 1.0 and 1.5</title>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>Old type</entry>
- <entry>New type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Country</entry>
- <entry>Territory (with value '2')</entry>
- </row>
- <row>
- <entry>Calendar</entry>
- <entry>Type (with value 'calendar')</entry>
- </row>
- <row>
- <entry>Month_Short</entry>
- <entry>Month (with array('gregorian', 'format', 'abbreviated')</entry>
- </row>
- <row>
- <entry>Month_Narrow</entry>
- <entry>Month (with array('gregorian', 'stand-alone', 'narrow')</entry>
- </row>
- <row>
- <entry>Month_Complete</entry>
- <entry>Months</entry>
- </row>
- <row>
- <entry>Day_Short</entry>
- <entry>Day (with array('gregorian', 'format', 'abbreviated')</entry>
- </row>
- <row>
- <entry>Day_Narrow</entry>
- <entry>Day (with array('gregorian', 'stand-alone', 'narrow')</entry>
- </row>
- <row>
- <entry>DateFormat</entry>
- <entry>Date</entry>
- </row>
- <row>
- <entry>TimeFormat</entry>
- <entry>Time</entry>
- </row>
- <row>
- <entry>Timezones</entry>
- <entry>CityToTimezone</entry>
- </row>
- <row>
- <entry>Currency</entry>
- <entry>NameToCurrency</entry>
- </row>
- <row>
- <entry>Currency_Sign</entry>
- <entry>CurrencySymbol</entry>
- </row>
- <row>
- <entry>Currency_Detail</entry>
- <entry>CurrencyToRegion</entry>
- </row>
- <row>
- <entry>Territory_Detail</entry>
- <entry>TerritoryToRegion</entry>
- </row>
- <row>
- <entry>Language_Detail</entry>
- <entry>LanguageToTerritory</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>
- The example below demonstrates how to obtain the names of things in different languages.
- </para>
- <example id="zend.locale.getdata.example-3">
- <title>getTranslationList</title>
- <programlisting language="php"><![CDATA[
- // prints the names of all countries in German language
- print_r(Zend_Locale::getTranslationList('country', 'de'));
- ]]></programlisting>
- </example>
- <para>
- The next example shows how to find the name of a language in another language, when the two letter
- iso country code is not known.
- </para>
- <example id="zend.locale.getdata.example-4">
- <title>Converting country name in one language to another</title>
- <programlisting language="php"><![CDATA[
- $code2name = Zend_Locale::getLanguageTranslationList('en_US');
- $name2code = array_flip($code2name);
- $frenchCode = $name2code['French'];
- echo Zend_Locale::getLanguageTranslation($frenchCode, 'de_AT');
- // output is the German name of the French language
- ]]></programlisting>
- </example>
- <para>
- To generate a list of all languages known by <classname>Zend_Locale</classname>, with each language name shown in its own language,
- try the example below in a web page. Similarly, <methodname>getCountryTranslationList()</methodname> and
- <methodname>getCountryTranslation()</methodname> could be used to create a table mapping your native language names for
- regions to the names of the regions shown in another language. Use a
- <code>try .. catch</code> block to handle exceptions that occur when using a locale that does not exist. Not
- all languages are also locales. In the example, below exceptions are ignored to prevent early termination.
- </para>
- <example id="zend.locale.getdata.example-6">
- <title>All Languages written in their native language</title>
- <programlisting language="php"><![CDATA[
- $list = Zend_Locale::getLanguageTranslationList('auto');
- foreach($list as $language => $content) {
- try {
- $output = Zend_Locale::getLanguageTranslation($language, $language);
- if (is_string($output)) {
- print "\n<br>[".$language."] ".$output;
- }
- } catch (Exception $e) {
- continue;
- }
- }
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.locale.getquestion">
- <title>Obtaining translations for "yes" and "no"</title>
- <para>
- Frequently, programs need to solicit a "yes" or "no" response from the user. Use <methodname>getQuestion()</methodname>
- to obtain an array containing the correct word(s) or regex strings to use for prompting the user in a
- particular $locale (defaults to the current object's locale). The returned array will contain the
- following informations :
- </para>
- <itemizedlist>
- <listitem>
- <para>
- <emphasis>yes and no</emphasis>: A generic string representation for yes
- and no responses. This will contain the first and most generic response from yesarray and
- noarray.
- </para>
- <para>
- <emphasis>yesarray and noarray</emphasis>: An array with all known yes and
- no responses. Several languages have more than just two responses. In general this is the
- full string and its abbreviation.
- </para>
- <para>
- <emphasis>yesexpr and noexpr</emphasis>: An generated regex which allows you
- to handle user response, and search for yes or no.
- </para>
- </listitem>
- </itemizedlist>
- <para>
- All of this informations are of course localized and depend on the set locale. See the following
- example for the informations you can receive:
- </para>
- <example id="zend.locale.getquestion.example-1">
- <title>getQuestion()</title>
- <programlisting language="php"><![CDATA[
- $locale = new Zend_Locale();
- // Question strings
- print_r($locale->getQuestion('de'));
- - - - Output - - -
- Array
- (
- [yes] => ja
- [no] => nein
- [yesarray] => Array
- (
- [0] => ja
- [1] => j
- )
- [noarray] => Array
- (
- [0] => nein
- [1] => n
- )
- [yesexpr] => ^([jJ][aA]?)|([jJ]?)
- [noexpr] => ^([nN]([eE][iI][nN])?)|([nN]?)
- )
- ]]></programlisting>
- </example>
- <note>
- <para>
- Until 1.0.3 <emphasis>yesabbr</emphasis> from the underlaying locale data was also
- available. Since 1.5 this information is no longer standalone available, but you will find the
- information from it within <emphasis>yesarray</emphasis>.
- </para>
- </note>
- </sect2>
- <sect2 id="zend.locale.getlocalelist">
- <title>Get a list of all known locales</title>
- <para>
- Sometimes you will want to get a list of all known locales. This can be used for several tasks
- like the creation of a selectbox. For this purpose you can use the static
- <methodname>getLocaleList()</methodname> method which will return a list of all known locales.
- </para>
- <example id="zend.locale.getlocalelist.example-1">
- <title>getLocaleList()</title>
- <programlisting language="php"><![CDATA[
- $localelist = Zend_Locale::getLocaleList();
- ]]></programlisting>
- </example>
- <note>
- <para>
- Note that the locales are returned as key of the array you will receive. The value is always
- a boolean <constant>TRUE</constant>.
- </para>
- </note>
- </sect2>
- <sect2 id="zend.locale.detection">
- <title>Detecting locales</title>
- <para>
- When you want to detect if a given input, regardless of its source, is a locale you should use
- the static <methodname>isLocale()</methodname> method. The first parameter of this method is the string which
- you want to check.
- </para>
- <example id="zend.locale.detection.example-1">
- <title>Simple locale detection</title>
- <programlisting language="php"><![CDATA[
- $input = 'to_RU';
- if (Zend_Locale::isLocale($input)) {
- print "'{$input}' is a locale";
- } else {
- print "Sorry... the given input is no locale";
- }
- ]]></programlisting>
- </example>
- <para>
- As you can see, the output of this method is always a boolean. There is only one reason you could
- get an exception when calling this method. When your system does not provide any locale and
- Zend Framework is not able to detect it automatically. Normally this shows that there is a problem
- with your OS in combination with <acronym>PHP</acronym>'s <methodname>setlocale()</methodname>.
- </para>
- <para>
- You should also note that any given locale string will automatically be degraded if the
- region part does not exist for this locale. In our previous example the language
- <code>'to'</code> does not exist in the region <code>'RU'</code>, but you will still get
- <constant>TRUE</constant> returned as <classname>Zend_Locale</classname> can work with
- the given input.
- </para>
- <para>
- Still it's sometimes useful to prevent this automatic degrading, and this is where the second
- parameter of <methodname>isLocale()</methodname> comes in place. The <code>strict</code> parameter defaults to
- <constant>FALSE</constant> and can be used to prevent degrading when set to <constant>TRUE</constant>.
- </para>
- <example id="zend.locale.detection.example-2">
- <title>Strict locale detection</title>
- <programlisting language="php"><![CDATA[
- $input = 'to_RU';
- if (Zend_Locale::isLocale($input, true)) {
- print "'{$input}' is a locale";
- } else {
- print "Sorry... the given input is no locale";
- }
- ]]></programlisting>
- </example>
- <para>
- Now that you are able to detect if a given string is a locale you could add locale aware behaviour
- to your own classes. But you will soon detect that this will always leads to the same 15 lines of
- code. Something like the following example:
- </para>
- <example id="zend.locale.detection.example-3">
- <title>Implement locale aware behaviour</title>
- <programlisting language="php"><![CDATA[
- if ($locale === null) {
- $locale = new Zend_Locale();
- }
- if (!Zend_Locale::isLocale($locale, true, false)) {
- if (!Zend_Locale::isLocale($locale, false, false)) {
- throw new Zend_Locale_Exception(
- "The locale '$locale' is no known locale");
- }
- $locale = new Zend_Locale($locale);
- }
- if ($locale instanceof Zend_Locale) {
- $locale = $locale->toString();
- }
- ]]></programlisting>
- </example>
- <para>
- With Zend Framework 1.8 we added a static <methodname>findLocale()</methodname> method which returns you a locale
- string which you can work with. It processes the following tasks:
- </para>
- <itemizedlist>
- <listitem>
- <para>
- Detects if a given string is a locale
- </para>
- </listitem>
- <listitem>
- <para>
- Degrades the locale if it does not exist in the given region
- </para>
- </listitem>
- <listitem>
- <para>
- Returns a previous set application wide locale if no input is given
- </para>
- </listitem>
- <listitem>
- <para>
- Detects the locale from browser when the previous detections failed
- </para>
- </listitem>
- <listitem>
- <para>
- Detects the locale from environment when the previous detections failed
- </para>
- </listitem>
- <listitem>
- <para>
- Detects the locale from framework when the previous detections failed
- </para>
- </listitem>
- <listitem>
- <para>
- Returns always a string which represents the found locale.
- </para>
- </listitem>
- </itemizedlist>
- <para>
- The following example shows how these checks and the above code can be simplified with one single call:
- </para>
- <example id="zend.locale.detection.example-4">
- <title>Locale aware behaviour as with Zend Framework 1.8</title>
- <programlisting language="php"><![CDATA[
- $locale = Zend_Locale::findLocale($inputstring);
- ]]></programlisting>
- </example>
- </sect2>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|