| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017 |
- <?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
- <command>$locale->toString()</command>.
- </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 <constant>FRAMEWORK</constant></link> first.
- The second parameter toggles between returning all matching locales or only the
- first or 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>.
- </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.getlocaletoterritory">
- <title>Get the locale by giving a territory</title>
- <para>
- When you only have the territory or country then it's also possible to get a locale
- from that information. You can manually search if there is a locale for this territory
- by using <methodname>getLocaleToTerritory()</methodname>. This method returns a
- locale for the given territory or <constant>NULL</constant> when there was has no locale
- been found.
- </para>
- <example id="zend.locale.getlocaletoterritory.example-1">
- <title>getLocaleToTerritory</title>
- <programlisting language="php"><![CDATA[
- $locale = Zend_Locale::getLocaleToTerritory('US');
- // returns 'en_US'
- ]]></programlisting>
- </example>
- <note>
- <title>Uppercase territories</title>
- <para>
- When you know that you are using a territory, then you should uppercase it.
- Otherwise you could get an in your eyes false locale in return when you use other
- methods. For example: When you give "om" then
- <methodname>getLocaleToTerritory()</methodname> returns you "ar_OM" as it knows that
- you mean a territory. But all other methods will return "om", as it's also a
- language.
- </para>
- <para>
- So when you know that the given string is a territory, eighter use
- <methodname>getLocaleToTerritory()</methodname> yourself before creating a locale,
- or uppercase the input.
- </para>
- </note>
- </sect2>
- <sect2 id="zend.locale.getdata">
- <title>Obtaining localized strings</title>
- <para>
- <methodname>getTranslationList()</methodname> gives you access to localized information
- 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 information for all languages. But not all information is
- completely available for all languages. Some of these types are also available through
- an own function for simplicity. See this list for detailed information.
- </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
- negation ('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 languages and the countries where they are spoken. The
- language is used as array key and the country 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 which are spoken within
- them. The country code is used as array key and the language code
- as array value. When several languages are spoken within a territory
- then 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 always returns 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: <command>array( 'calendar', 'context', 'format',
- 'month number')</command>. 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 translation for 'AM' in the expected locale. If you want to
- receive data for other calendars provide a 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 translation for 'PM' in the expected locale. If you want to
- receive data for other calendars provide a 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 a 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 a 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 a 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 negation ('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 territory where a given language is used. The language has
- to be given as <acronym>ISO</acronym> language code for example 'en' for
- english. When the given language is spoken within multiple territories
- then these territories are separated with a whitespace character
- </entry>
- </row>
- <row>
- <entry><emphasis>LanguageToTerritory</emphasis></entry>
- <entry>
- Returns the language which is spoken within a given territory. The
- territory has to be given as <constant>ISO3166</constant> code for
- example 'IT' for italia. When multiple languages are spoken within the
- given territory then these languages 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 <command>try .. catch</command> 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 information :
- </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>: A generated regex which allows you
- to handle user response, and search for yes or no.
- </para>
- </listitem>
- </itemizedlist>
- <para>
- All of this information are of course localized and depend on the set locale. See the
- following example for the information 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
- '<property>to</property>' does not exist in the region '<property>RU</property>', 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
- <property>strict</property> 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 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 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>
- Upgrades the locale when it is detected as region without language
- </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:
- -->
|