| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016 |
- <?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>.
- </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 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 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:
- <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 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 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 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
- <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 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:
- -->
|