Zend_Locale-Functions.xml 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.locale.functions">
  4. <title>Using Zend_Locale</title>
  5. <para>
  6. <classname>Zend_Locale</classname> also provides localized information about locales for each locale,
  7. including localized names for other locales, days of the week, month names, etc.
  8. </para>
  9. <sect2 id="zend.locale.copying">
  10. <title>Copying, Cloning, and Serializing Locale Objects</title>
  11. <para>
  12. Use
  13. <ulink url="http://php.net/language.oop5.cloning">object cloning</ulink>
  14. to duplicate a locale object exactly and efficiently. Most locale-aware methods also accept string
  15. representations of locales, such as the result of <code>$locale->toString()</code>.
  16. </para>
  17. <example id="zend.locale.copying.example-1">
  18. <title>clone</title>
  19. <programlisting language="php"><![CDATA[
  20. $locale = new Zend_Locale('ar');
  21. // Save the $locale object as a serialization
  22. $serializedLocale = $locale->serialize();
  23. // re-create the original object
  24. $localeObject = unserialize($serializedLocale);
  25. // Obtain a string identification of the locale
  26. $stringLocale = $locale->toString();
  27. // Make a cloned copy of the $local object
  28. $copiedLocale = clone $locale;
  29. print "copied: ", $copiedLocale->toString();
  30. // PHP automatically calls toString() via __toString()
  31. print "copied: ", $copiedLocale;
  32. ]]></programlisting>
  33. </example>
  34. </sect2>
  35. <sect2 id="zend.locale.equals">
  36. <title>Equality</title>
  37. <para>
  38. <classname>Zend_Locale</classname> also provides a convenience function to compare two locales. All locale-aware
  39. classes should provide a similar equality check.
  40. </para>
  41. <example id="zend.locale.equals.example-1">
  42. <title>Check for equal locales</title>
  43. <programlisting language="php"><![CDATA[
  44. $locale = new Zend_Locale();
  45. $mylocale = new Zend_Locale('en_US');
  46. // Check if locales are equal
  47. if ($locale->equals($mylocale)) {
  48. print "Locales are equal";
  49. }
  50. ]]></programlisting>
  51. </example>
  52. </sect2>
  53. <sect2 id="zend.locale.getdefault">
  54. <title>Default locales</title>
  55. <para>
  56. The method <code>getDefault()</code> returns an array of relevant locales using information from the user's
  57. web browser (if available), information from the environment of the host server, and ZF settings. As with
  58. the constructor for <classname>Zend_Locale</classname>, the first parameter selects a preference of which information
  59. to consider
  60. <link linkend="zend.locale.selection">(<code>BROWSER</code>, <code>ENVIRONMENT</code>, or <code>FRAMEWORK)</code>
  61. </link>
  62. first. The second parameter toggles between returning all matching locales or only the first/best match.
  63. Locale-aware components normally use only the first locale. A quality rating is included, when available.
  64. </para>
  65. <example id="zend.locale.getdefault.example-1">
  66. <title>Get default locales</title>
  67. <programlisting language="php"><![CDATA[
  68. $locale = new Zend_Locale();
  69. // Return all default locales
  70. $found = $locale->getDefault();
  71. print_r($found);
  72. // Return only browser locales
  73. $found2 = $locale->getDefault(Zend_Locale::BROWSER,TRUE);
  74. print_r($found2);
  75. ]]></programlisting>
  76. </example>
  77. <para>
  78. To obtain only the default locales relevant to the
  79. <link linkend="zend.locale.selection"><code>BROWSER</code>, <code>ENVIRONMENT</code>, or <code>FRAMEWORK</code>
  80. </link>
  81. , use the corresponding method:
  82. <itemizedlist>
  83. <listitem>
  84. <para>
  85. <code>getEnvironment()</code>
  86. </para>
  87. </listitem>
  88. <listitem>
  89. <para>
  90. <code>getBrowser()</code>
  91. </para>
  92. </listitem>
  93. <listitem>
  94. <para>
  95. <code>getLocale()</code>
  96. </para>
  97. </listitem>
  98. </itemizedlist>
  99. </para>
  100. </sect2>
  101. <sect2 id="zend.locale.setlocale">
  102. <title>Set a new locale</title>
  103. <para>
  104. A new locale can be set with the function <code>setLocale()</code>. This function takes a locale string as
  105. parameter. If no locale is given, a locale is
  106. <link linkend="zend.locale.selection">automatically selected</link>.
  107. Since <classname>Zend_Locale</classname> objects are "light", this method exists primarily to cause side-effects for code that
  108. have references to the existing instance object.
  109. </para>
  110. <example id="zend.locale.setlocale.example-1">
  111. <title>setLocale</title>
  112. <programlisting language="php"><![CDATA[
  113. $locale = new Zend_Locale();
  114. // Actual locale
  115. print $locale->toString();
  116. // new locale
  117. $locale->setLocale('aa_DJ');
  118. print $locale->toString();
  119. ]]></programlisting>
  120. </example>
  121. </sect2>
  122. <sect2 id="zend.locale.getlocale">
  123. <title>Getting the language and region</title>
  124. <para>
  125. Use <code>getLanguage()</code> to obtain a string containing the two character language code from the string
  126. locale identifier. Use <code>getRegion()</code> to obtain a string containing the two character region code
  127. from the string locale identifier.
  128. </para>
  129. <example id="zend.locale.getlocale.example-1">
  130. <title>getLanguage and getRegion</title>
  131. <programlisting language="php"><![CDATA[
  132. $locale = new Zend_Locale();
  133. // if locale is 'de_AT' then 'de' will be returned as language
  134. print $locale->getLanguage();
  135. // if locale is 'de_AT' then 'AT' will be returned as region
  136. print $locale->getRegion();
  137. ]]></programlisting>
  138. </example>
  139. </sect2>
  140. <sect2 id="zend.locale.getdata">
  141. <title>Obtaining localized strings</title>
  142. <para>
  143. <code>getTranslationList()</code> gives you access to localized informations of several types. These
  144. information are useful if you want to display localized data to a customer without the need
  145. of translating it. They are already available for your usage.
  146. </para>
  147. <para>
  148. The requested list of information is always returned as named array. If you want to give more than
  149. one value to a explicit type where you wish to receive values from, you have to give an array
  150. instead of multiple values.
  151. </para>
  152. <example id="zend.locale.getdata.example-1">
  153. <title>getTranslationList</title>
  154. <programlisting language="php"><![CDATA[
  155. $list = Zend_Locale::getTranslationList('language', 'de_AT');
  156. print_r ($list);
  157. // example key -> value pairs...
  158. // [de] -> Deutsch
  159. // [en] -> Englisch
  160. // use one of the returned key as value for the getTranslation() method
  161. // of another language
  162. print Zend_Locale::getTranslation('de', 'language', 'zh');
  163. // returns the translation for the language 'de' in chinese
  164. ]]></programlisting>
  165. </example>
  166. <para>
  167. You can receive this informations for all languages. But not all of the informations are completely
  168. available for all languages. Some of these types are also available through an own function for
  169. simplicity. See this list for detailed informations.
  170. </para>
  171. <table id="zend.locale.getdata.table-1">
  172. <title>Details for getTranslationList($type = null, $locale = null, $value = null)</title>
  173. <tgroup cols="2">
  174. <thead>
  175. <row>
  176. <entry>Type</entry>
  177. <entry>Description</entry>
  178. </row>
  179. </thead>
  180. <tbody>
  181. <row>
  182. <entry><emphasis>Language</emphasis></entry>
  183. <entry>Returns a localized list of all languages. The language part of the locale
  184. is returned as key and the translation as value</entry>
  185. </row>
  186. <row>
  187. <entry><emphasis>Script</emphasis></entry>
  188. <entry>Returns a localized list of all scripts. The script is returned as key and the
  189. translation as value</entry>
  190. </row>
  191. <row>
  192. <entry><emphasis>Territory</emphasis></entry>
  193. <entry>Returns a localized list of all territories. This contains countries,
  194. continents and territories. To get only territories and continents
  195. use '1' as value. To get only countries use '2' as value. The country part of
  196. the locale is used as key where applicable. In the other case the official ISO
  197. code for this territory is used. The translated territory is returned as value.
  198. When you omit the value you will get a list with both.</entry>
  199. </row>
  200. <row>
  201. <entry><emphasis>Variant</emphasis></entry>
  202. <entry>Returns a localized list of known variants of scripts. The variant is
  203. returned as key and the translation as value</entry>
  204. </row>
  205. <row>
  206. <entry><emphasis>Key</emphasis></entry>
  207. <entry>Returns a localized list of known keys. This keys are generic values used
  208. in translation. These are normally calendar, collation and currency. The key
  209. is returned as array key and the translation as value</entry>
  210. </row>
  211. <row>
  212. <entry><emphasis>Type</emphasis></entry>
  213. <entry>Returns a localized list of known types of keys. These are variants of types
  214. of calendar representations and types of collations. When you use 'collation' as
  215. value you will get all types of collations returned. When you use 'calendar' as
  216. value you will get all types of calendars returned. When you omit the value you
  217. will get a list all both returned. The type is used as key and the translation as
  218. value</entry>
  219. </row>
  220. <row>
  221. <entry><emphasis>Layout</emphasis></entry>
  222. <entry>Returns a list of rules which describes how to format special text parts</entry>
  223. </row>
  224. <row>
  225. <entry><emphasis>Characters</emphasis></entry>
  226. <entry>Returns a list of allowed characters within this locale</entry>
  227. </row>
  228. <row>
  229. <entry><emphasis>Delimiters</emphasis></entry>
  230. <entry>Returns a list of allowed quoting characters for this locale</entry>
  231. </row>
  232. <row>
  233. <entry><emphasis>Measurement</emphasis></entry>
  234. <entry>Returns a list of known measurement values. This list is depreciated</entry>
  235. </row>
  236. <row>
  237. <entry><emphasis>Months</emphasis></entry>
  238. <entry>Returns a list of all month representations within this locale. There are
  239. several different representations which are all returned as sub array. If you omit
  240. the value you will get a list of all months from the 'gregorian' calendar returned.
  241. You can give any known calendar as value to get a list of months from this calendar
  242. returned. Use <link linkend="zend.date.introduction">Zend_Date</link> for
  243. simplicity</entry>
  244. </row>
  245. <row>
  246. <entry><emphasis>Month</emphasis></entry>
  247. <entry>Returns a localized list of all month names for this locale. If you omit the
  248. value you will get the normally used gregorian full name of the months where each
  249. month number is used as key and the translated month is returned as value. You
  250. can get the months for different calendars and formats if you give an array as value.
  251. The first array entry has to be the calendar, the second the used context and the
  252. third the width to return. Use <link linkend="zend.date.introduction">Zend_Date</link>
  253. for simplicity</entry>
  254. </row>
  255. <row>
  256. <entry><emphasis>Days</emphasis></entry>
  257. <entry>Returns a list of all day representations within this locale. There are
  258. several different representations which are all returned as sub array. If you omit
  259. the value you will get a list of all days from the 'gregorian' calendar returned.
  260. You can give any known calendar as value to get a list of days from this calendar
  261. returned. Use <link linkend="zend.date.introduction">Zend_Date</link> for
  262. simplicity</entry>
  263. </row>
  264. <row>
  265. <entry><emphasis>Day</emphasis></entry>
  266. <entry>Returns a localized list of all day names for this locale. If you omit the
  267. value you will get the normally used gregorian full name of the days where the
  268. english day abbreviation is used as key and the translated day is returned as
  269. value. You can get the days for different calendars and formats if you give an
  270. array as value. The first array entry has to be the calendar, the second the used
  271. context and the third the width to return. Use
  272. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  273. </row>
  274. <row>
  275. <entry><emphasis>Week</emphasis></entry>
  276. <entry>Returns a list of values used for proper week calculations within a locale.
  277. Use <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  278. </row>
  279. <row>
  280. <entry><emphasis>Quarters</emphasis></entry>
  281. <entry>Returns a list of all quarter representations within this locale. There are
  282. several different representations which are all returned as sub array. If you omit
  283. the value you will get a list of all quarters from the 'gregorian' calendar returned.
  284. You can give any known calendar as value to get a list of quarters from this calendar
  285. returned</entry>
  286. </row>
  287. <row>
  288. <entry><emphasis>Quarter</emphasis></entry>
  289. <entry>Returns a localized list of all quarter names for this locale. If you omit the
  290. value you will get the normally used gregorian full name of the quarters where each
  291. quarter number is used as key and the translated quarter is returned as value. You
  292. can get the quarters for different calendars and formats if you give an array as
  293. value. The first array entry has to be the calendar, the second the used context
  294. and the third the width to return</entry>
  295. </row>
  296. <row>
  297. <entry><emphasis>Eras</emphasis></entry>
  298. <entry>Returns a list of all era representations within this locale. If you omit
  299. the value you will get a list of all eras from the 'gregorian' calendar returned.
  300. You can give any known calendar as value to get a list of eras from this calendar
  301. returned</entry>
  302. </row>
  303. <row>
  304. <entry><emphasis>Era</emphasis></entry>
  305. <entry>Returns a localized list of all era names for this locale. If you omit the
  306. value you will get the normally used gregorian full name of the eras where each
  307. era number is used as key and the translated era is returned as value. You
  308. can get the eras for different calendars and formats if you give an array as
  309. value. The first array entry has to be the calendar and the second the width to
  310. return</entry>
  311. </row>
  312. <row>
  313. <entry><emphasis>Date</emphasis></entry>
  314. <entry>Returns a localized list of all date formats for this locale. The name of the
  315. dateformat is used as key and the format itself as value.If you omit the value you
  316. will get the date formats for the gregorian calendar returned. You can get the
  317. date formats for different calendars if you give the wished calendar as string.
  318. Use <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  319. </row>
  320. <row>
  321. <entry><emphasis>Time</emphasis></entry>
  322. <entry>Returns a localized list of all time formats for this locale. The name of the
  323. timeformat is used as key and the format itself as value. If you omit the value you
  324. will get the time formats for the gregorian calendar returned. You can get the
  325. time formats for different calendars if you give the wished calendar as string.
  326. Use <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  327. </row>
  328. <row>
  329. <entry><emphasis>DateTime</emphasis></entry>
  330. <entry>Returns a localized list of all known date-time formats for this locale. The name
  331. of the date-time format is used as key and the format itself as value. If you
  332. omit the value you will get the date-time formats for the gregorian calendar returned.
  333. You can get the date-time formats for different calendars if you give the wished
  334. calendar as string. Use <link linkend="zend.date.introduction">Zend_Date</link>
  335. for simplicity</entry>
  336. </row>
  337. <row>
  338. <entry><emphasis>Field</emphasis></entry>
  339. <entry>Returns a localized list of date fields which can be used to display calendars
  340. or date strings like 'month' or 'year' in a wished language. If you omit the value
  341. you will get this list for the gregorian calendar returned. You can get the
  342. list for different calendars if you give the wished calendar as string</entry>
  343. </row>
  344. <row>
  345. <entry><emphasis>Relative</emphasis></entry>
  346. <entry>Returns a localized list of relative dates which can be used to display
  347. textual relative dates like 'yesterday' or 'tomorrow' in a wished language.
  348. If you omit the value you will get this list for the gregorian calendar
  349. returned. You can get the list for different calendars if you give the wished
  350. calendar as string</entry>
  351. </row>
  352. <row>
  353. <entry><emphasis>Symbols</emphasis></entry>
  354. <entry>Returns a localized list of characters used for number representations</entry>
  355. </row>
  356. <row>
  357. <entry><emphasis>NameToCurrency</emphasis></entry>
  358. <entry>Returns a localized list of names for currencies. The currency is used as key
  359. and the translated name as value. Use
  360. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  361. </row>
  362. <row>
  363. <entry><emphasis>CurrencyToName</emphasis></entry>
  364. <entry>Returns a list of currencies for localized names. The translated name is used
  365. as key and the currency as value. Use
  366. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  367. </row>
  368. <row>
  369. <entry><emphasis>CurrencySymbol</emphasis></entry>
  370. <entry>Returns a list of known localized currency symbols for currencies. The
  371. currency is used as key and the symbol as value. Use
  372. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  373. </row>
  374. <row>
  375. <entry><emphasis>Question</emphasis></entry>
  376. <entry>Returns a list of localized strings for acceptance ('yes') and
  377. negotation ('no'). Use
  378. <link linkend="zend.locale.getquestion">Zend_Locale's getQuestion method</link>
  379. for simplicity</entry>
  380. </row>
  381. <row>
  382. <entry><emphasis>CurrencyFraction</emphasis></entry>
  383. <entry>Returns a list of fractions for currency values. The currency is used as key and
  384. the fraction as integer value. Use
  385. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  386. </row>
  387. <row>
  388. <entry><emphasis>CurrencyRounding</emphasis></entry>
  389. <entry>Returns a list of how to round which currency. The currency is used as key and
  390. the rounding as integer value. Use
  391. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  392. </row>
  393. <row>
  394. <entry><emphasis>CurrencyToRegion</emphasis></entry>
  395. <entry>Returns a list of currencies which are known to be used within a region.
  396. The ISO3166 value ('region') is used as array key and the ISO4217 value
  397. ('currency') as array value. Use
  398. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  399. </row>
  400. <row>
  401. <entry><emphasis>RegionToCurrency</emphasis></entry>
  402. <entry>Returns a list of regions where a currency is used . The ISO4217 value ('currency')
  403. is used as array key and the ISO3166 value ('region') as array value. When a currency
  404. is used in several regions these regions are separated with a whitespace. Use
  405. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  406. </row>
  407. <row>
  408. <entry><emphasis>RegionToTerritory</emphasis></entry>
  409. <entry>Returns a list of territories with the countries or sub territories which are
  410. included within that territory. The ISO territory code ('territory') is used as
  411. array key and the ISO3166 value ('region') as array value. When a territory contains
  412. several regions these regions are separated with a whitespace</entry>
  413. </row>
  414. <row>
  415. <entry><emphasis>TerritoryToRegion</emphasis></entry>
  416. <entry>Returns a list of regions and the territories where these regions are located.
  417. The ISO3166 code ('region') is used as array key and the ISO territory code
  418. ('territory') as array value. When a region is located in several territories
  419. these territories are separated with a whitespace</entry>
  420. </row>
  421. <row>
  422. <entry><emphasis>ScriptToLanguage</emphasis></entry>
  423. <entry>Returns a list of scripts which are used within a language. The language code
  424. is used as array key and the script code as array value. When a language contains
  425. several scripts these scripts are separated with a whitespace</entry>
  426. </row>
  427. <row>
  428. <entry><emphasis>LanguageToScript</emphasis></entry>
  429. <entry>Returns a list of languages which are using a script. The script code
  430. is used as array key and the language code as array value. When a script is used
  431. in several languages these languages are separated with a whitespace</entry>
  432. </row>
  433. <row>
  434. <entry><emphasis>TerritoryToLanguage</emphasis></entry>
  435. <entry>Returns a list of countries which are using a language. The country code
  436. is used as array key and the language code as array value. When a language is used in
  437. several countries these countries are separated with a whitespace</entry>
  438. </row>
  439. <row>
  440. <entry><emphasis>LanguageToTerritory</emphasis></entry>
  441. <entry>Returns a list of countries and the languages spoken within these countries.
  442. The country code is used as array key and the language code as array value. When
  443. a territory is using several languages these languages are separated with a
  444. whitespace</entry>
  445. </row>
  446. <row>
  447. <entry><emphasis>TimezoneToWindows</emphasis></entry>
  448. <entry>Returns a list of windows timezones and the related ISO timezone. The windows
  449. timezone is used as array key and the ISO timezone as array value</entry>
  450. </row>
  451. <row>
  452. <entry><emphasis>WindowsToTimezone</emphasis></entry>
  453. <entry>Returns a list of ISO timezones and the related windows timezone. The ISO
  454. timezone is used as array key and the windows timezone as array value</entry>
  455. </row>
  456. <row>
  457. <entry><emphasis>TerritoryToTimezone</emphasis></entry>
  458. <entry>Returns a list of regions or territories and the related ISO timezone. The
  459. ISO timezone is used as array key and the territory code as array value</entry>
  460. </row>
  461. <row>
  462. <entry><emphasis>TimezoneToTerritory</emphasis></entry>
  463. <entry>Returns a list of timezones and the related region or territory code. The
  464. region or territory code is used as array key and the ISO timezone as array
  465. value</entry>
  466. </row>
  467. <row>
  468. <entry><emphasis>CityToTimezone</emphasis></entry>
  469. <entry>Returns a localized list of cities which can be used as translation for a
  470. related timezone. Not for all timezones is a translation available, but for a
  471. user is the real city written in his languages more accurate than the ISO name
  472. of this timezone. The ISO timezone is used as array key and the translated
  473. city as array value</entry>
  474. </row>
  475. <row>
  476. <entry><emphasis>TimezoneToCity</emphasis></entry>
  477. <entry>Returns a list of timezones for localized city names. The localized city is
  478. used as array key and the ISO timezone name as array value</entry>
  479. </row>
  480. <row>
  481. <entry><emphasis>PhoneToTerritory</emphasis></entry>
  482. <entry>Returns a list of phone codes which are known to be used within a territory.
  483. The territory (region) is used as array key and the telephone code
  484. as array value</entry>
  485. </row>
  486. <row>
  487. <entry><emphasis>TerritoryToPhone</emphasis></entry>
  488. <entry>Returns a list of territories where a phone is used . The phone code
  489. is used as array key and the territory (region) as array value. When a
  490. phone code is used in several territories these territories are separated with a
  491. whitespace</entry>
  492. </row>
  493. <row>
  494. <entry><emphasis>NumericToTerritory</emphasis></entry>
  495. <entry>Returns a list of 3 digit number codes for territories.
  496. The territory (region) is used as array key and the 3 digit number code
  497. as array value</entry>
  498. </row>
  499. <row>
  500. <entry><emphasis>TerritoryToNumeric</emphasis></entry>
  501. <entry>Returns a list of territories with their 3 digit number code. The 3 digit
  502. number code is used as array key and the territory (region) as array value
  503. </entry>
  504. </row>
  505. <row>
  506. <entry><emphasis>Alpha3ToTerritory</emphasis></entry>
  507. <entry>Returns a list of 3 sign character codes for territories.
  508. The territory (region) is used as array key and the 3 sign character code
  509. as array value</entry>
  510. </row>
  511. <row>
  512. <entry><emphasis>TerritoryToAlpha3</emphasis></entry>
  513. <entry>Returns a list of territories with their 3 sign character code. The 3 sign
  514. character code is used as array key and the territory (region) as array value
  515. </entry>
  516. </row>
  517. <row>
  518. <entry><emphasis>PostalToTerritory</emphasis></entry>
  519. <entry>Returns a list of territories with a regex for postal codes which are
  520. included within that territory. The ISO territory code ('territory') is used as
  521. array key and the regex as array value.</entry>
  522. </row>
  523. <row>
  524. <entry><emphasis>NumberingSystem</emphasis></entry>
  525. <entry>
  526. Returns a list of scripts with the notation for digits used within the
  527. script
  528. </entry>
  529. </row>
  530. <row>
  531. <entry><emphasis>FallbackToChar</emphasis></entry>
  532. <entry>
  533. Returns a list of replacement characters for often used unicode characters.
  534. This can be used to replace "©" with "(C)" for example
  535. </entry>
  536. </row>
  537. <row>
  538. <entry><emphasis>CharToFallback</emphasis></entry>
  539. <entry>
  540. Returns a list of unicode characters for often used replacement characters.
  541. This can be used to replace "(C)" with "©" for example
  542. </entry>
  543. </row>
  544. <row>
  545. <entry><emphasis>LocaleUpgrade</emphasis></entry>
  546. <entry>
  547. Returns a list of locale dependencies which can be used to upgrade a
  548. language to a full qualified locale
  549. </entry>
  550. </row>
  551. </tbody>
  552. </tgroup>
  553. </table>
  554. <para>
  555. If you are in need of a single translated value, you can use the <code>getTranslation()</code>
  556. method. It returns always a string but it accepts some different types than the
  557. <code>getTranslationList()</code> method. Also value is the same as before with one difference.
  558. You have to give the detail you want to get returned as additional value.
  559. </para>
  560. <note>
  561. <para>
  562. Because you have almost always give a value as detail this parameter has to be given
  563. as first parameter. This differs from the <code>getTranslationList()</code> method.
  564. </para>
  565. </note>
  566. <para>
  567. See the following table for detailed information:
  568. </para>
  569. <table id="zend.locale.getdata.table-2">
  570. <title>Details for getTranslation($value = null, $type = null, $locale = null)</title>
  571. <tgroup cols="2">
  572. <thead>
  573. <row>
  574. <entry>Type</entry>
  575. <entry>Description</entry>
  576. </row>
  577. </thead>
  578. <tbody>
  579. <row>
  580. <entry><emphasis>Language</emphasis></entry>
  581. <entry>Returns a translation for a language. To select the wished translation
  582. you must give the language code as value</entry>
  583. </row>
  584. <row>
  585. <entry><emphasis>Script</emphasis></entry>
  586. <entry>Returns a translation for a script. To select the wished translation you
  587. must give the script code as value</entry>
  588. </row>
  589. <row>
  590. <entry><emphasis>Territory</emphasis> or
  591. <emphasis>Country</emphasis></entry>
  592. <entry>Returns a translation for a territory. This can be countries, continents
  593. and territories. To select the wished variant you must give the territory
  594. code as value</entry>
  595. </row>
  596. <row>
  597. <entry><emphasis>Variant</emphasis></entry>
  598. <entry>Returns a translation for a script variant. To select the wished variant
  599. you must give the variant code as value</entry>
  600. </row>
  601. <row>
  602. <entry><emphasis>Key</emphasis></entry>
  603. <entry>Returns translation for a known keys. This keys are generic values used
  604. in translation. These are normally calendar, collation and currency. To
  605. select the wished key you must give the key code as value</entry>
  606. </row>
  607. <row>
  608. <entry><emphasis>DefaultCalendar</emphasis></entry>
  609. <entry>Returns the default calendar for the given locale. For most locales this
  610. will be 'gregorian'. Use
  611. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  612. </row>
  613. <row>
  614. <entry><emphasis>MonthContext</emphasis></entry>
  615. <entry>Returns the default context for months which is used within the given
  616. calendar. If you omit the value the 'gregorian' calendar will be used. Use
  617. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  618. </row>
  619. <row>
  620. <entry><emphasis>DefaultMonth</emphasis></entry>
  621. <entry>Returns the default format for months which is used within the given
  622. calendar. If you omit the value the 'gregorian' calendar will be used. Use
  623. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  624. </row>
  625. <row>
  626. <entry><emphasis>Month</emphasis></entry>
  627. <entry>Returns a translation for a month. You have to give the number of the month
  628. as integer value. It has to be between 1 and 12. If you want to receive data for
  629. other calendars, contexts or formats, then you must give an array instead of an
  630. integer with the expected values. The array has to look like this: <code>array(
  631. 'calendar', 'context', 'format', 'month number')</code>. If you give only an
  632. integer then the default values are the 'gregorian' calendar, the context
  633. 'format' and the format 'wide'. Use
  634. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  635. </row>
  636. <row>
  637. <entry><emphasis>DayContext</emphasis></entry>
  638. <entry>Returns the default context for ´days which is used within the given
  639. calendar. If you omit the value the 'gregorian' calendar will be used. Use
  640. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  641. </row>
  642. <row>
  643. <entry><emphasis>DefaultDay</emphasis></entry>
  644. <entry>Returns the default format for days which is used within the given
  645. calendar. If you omit the value the 'gregorian' calendar will be used. Use
  646. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  647. </row>
  648. <row>
  649. <entry><emphasis>Day</emphasis></entry>
  650. <entry>Returns a translation for a day. You have to give the english abbreviation
  651. of the day as string value ('sun', 'mon', etc.). If you want to receive data
  652. for other calendars, contexts or format, then you must give an array instead of
  653. an integer with the expected values. The array has to look like this:
  654. <code>array('calendar', 'context', 'format', 'day abbreviation')</code>. If you
  655. give only an string then the default values are the 'gregorian' calendar,
  656. the context 'format' and the format 'wide'. Use
  657. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  658. </row>
  659. <row>
  660. <entry><emphasis>Quarter</emphasis></entry>
  661. <entry>Returns a translation for a quarter. You have to give the number of the
  662. quarter as integer and it has to be between 1 and 4. If you want to receive
  663. data for other calendars, contexts or formats, then you must give an array
  664. instead of an integer with the expected values. The array has to look like this:
  665. <code>array('calendar', 'context', 'format', 'quarter number')</code>. If you
  666. give only an string then the default values are the 'gregorian' calendar,
  667. the context 'format' and the format 'wide'</entry>
  668. </row>
  669. <row>
  670. <entry><emphasis>Am</emphasis></entry>
  671. <entry>Returns a translation for 'AM' in a expected locale. If you want to receive
  672. data for other calendars an string with the expected calendar. If you omit the
  673. value then the 'gregorian' calendar will be used. Use
  674. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  675. </row>
  676. <row>
  677. <entry><emphasis>Pm</emphasis></entry>
  678. <entry>Returns a translation for 'PM' in a expected locale. If you want to receive
  679. data for other calendars an string with the expected calendar. If you omit the
  680. value then the 'gregorian' calendar will be used. Use
  681. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  682. </row>
  683. <row>
  684. <entry><emphasis>Era</emphasis></entry>
  685. <entry>Returns a translation for an era within a locale. You have to give the era
  686. number as string or integer. If you want to receive data for other calendars or
  687. formats, then you must give an array instead of the era number with the expected
  688. values. The array has to look like this:
  689. <code>array('calendar', 'format', 'era number')</code>. If you give only an
  690. string then the default values are the 'gregorian' calendar and the 'abbr'
  691. format</entry>
  692. </row>
  693. <row>
  694. <entry><emphasis>DefaultDate</emphasis></entry>
  695. <entry>Returns the default date format which is used within the given
  696. calendar. If you omit the value the 'gregorian' calendar will be used. Use
  697. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  698. </row>
  699. <row>
  700. <entry><emphasis>Date</emphasis></entry>
  701. <entry>Returns the date format for an given calendar or format within a locale.
  702. If you omit the value then the 'gregorian' calendar will be used with the
  703. 'medium' format. If you give a string then the 'gregorian' calendar will be
  704. used with the given format. Or you can also give an array which will have to
  705. look like this: <code>array('calendar', 'format')</code>. Use
  706. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  707. </row>
  708. <row>
  709. <entry><emphasis>DefaultTime</emphasis></entry>
  710. <entry>Returns the default time format which is used within the given
  711. calendar. If you omit the value the 'gregorian' calendar will be used. Use
  712. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  713. </row>
  714. <row>
  715. <entry><emphasis>Time</emphasis></entry>
  716. <entry>Returns the time format for an given calendar or format within a locale.
  717. If you omit the value then the 'gregorian' calendar will be used with the
  718. 'medium' format. If you give a string then the 'gregorian' calendar will be
  719. used with the given format. Or you can also give an array which will have to
  720. look like this: <code>array('calendar', 'format')</code>. Use
  721. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  722. </row>
  723. <row>
  724. <entry><emphasis>DateTime</emphasis></entry>
  725. <entry>Returns the datetime format for the given locale which indicates how to
  726. display date with times in the same string within the given calendar. If you
  727. omit the value the 'gregorian' calendar will be used. Use
  728. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  729. </row>
  730. <row>
  731. <entry><emphasis>Field</emphasis></entry>
  732. <entry>Returns a translated date field which can be used to display calendars or
  733. date strings like 'month' or 'year' in a wished language. You must give the
  734. field which has to be returned as string. In this case the 'gregorian'
  735. calendar will be used. You can get the field for other calendar formats if you
  736. give an array which has to look like this:
  737. <code>array('calendar', 'date field')</code></entry>
  738. </row>
  739. <row>
  740. <entry><emphasis>Relative</emphasis></entry>
  741. <entry>Returns a translated date which is relative to today which can include date
  742. strings like 'yesterday' or 'tomorrow' in a wished language. You have to give
  743. the number of days relative to tomorrow to receive the expected string. Yesterday
  744. would be '-1', tomorrow '1' and so on. This will use the 'gregorian' calendar. If
  745. you want to get relative dates for other calendars you will have to give an array
  746. which has to look like this: <code>array('calendar', 'relative days')</code>. Use
  747. <link linkend="zend.date.introduction">Zend_Date</link> for simplicity</entry>
  748. </row>
  749. <row>
  750. <entry><emphasis>DecimalNumber</emphasis></entry>
  751. <entry>Returns the format for decimal numbers within a given locale. Use
  752. <link linkend="zend.locale.parsing">Zend_Locale_Format</link> for simplicity</entry>
  753. </row>
  754. <row>
  755. <entry><emphasis>ScientificNumber</emphasis></entry>
  756. <entry>Returns the format for scientific numbers within a given locale</entry>
  757. </row>
  758. <row>
  759. <entry><emphasis>PercentNumber</emphasis></entry>
  760. <entry>Returns the format for percentage numbers within a given locale</entry>
  761. </row>
  762. <row>
  763. <entry><emphasis>CurrencyNumber</emphasis></entry>
  764. <entry>Returns the format for displaying currency numbers within a given locale. Use
  765. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  766. </row>
  767. <row>
  768. <entry><emphasis>NameToCurrency</emphasis></entry>
  769. <entry>Returns the translated name for a given currency. The currency has to be
  770. given in ISO format which is for example 'EUR' for the currency 'euro'. Use
  771. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  772. </row>
  773. <row>
  774. <entry><emphasis>CurrencyToName</emphasis></entry>
  775. <entry>Returns a currency for a given localized name. Use
  776. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  777. </row>
  778. <row>
  779. <entry><emphasis>CurrencySymbol</emphasis></entry>
  780. <entry>Returns the used symbol for a currency within a given locale. Not for all
  781. currencies exists a symbol. Use
  782. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  783. </row>
  784. <row>
  785. <entry><emphasis>Question</emphasis></entry>
  786. <entry>Returns a localized string for acceptance ('yes') and
  787. negotation ('no'). You have to give either 'yes' or 'no' as value to receive the
  788. expected string. Use
  789. <link linkend="zend.locale.getquestion">Zend_Locale's getQuestion method</link>
  790. for simplicity</entry>
  791. </row>
  792. <row>
  793. <entry><emphasis>CurrencyFraction</emphasis></entry>
  794. <entry>Returns the fraction to use for a given currency. You must give the currency
  795. as ISO value. Use <link linkend="zend.currency.introduction">Zend_Currency</link>
  796. for simplicity</entry>
  797. </row>
  798. <row>
  799. <entry><emphasis>CurrencyRounding</emphasis></entry>
  800. <entry>Returns how to round a given currency. You must give the currency
  801. as ISO value. If you omit the currency then the 'DEFAULT' rounding will be
  802. returned. Use <link linkend="zend.currency.introduction">Zend_Currency</link>
  803. for simplicity</entry>
  804. </row>
  805. <row>
  806. <entry><emphasis>CurrencyToRegion</emphasis></entry>
  807. <entry>Returns the currency for a given region. The region code has to be given
  808. as ISO3166 string for example 'AT' for austria. Use
  809. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  810. </row>
  811. <row>
  812. <entry><emphasis>RegionToCurrency</emphasis></entry>
  813. <entry>Returns the regions where a currency is used. The currency has to be given
  814. as ISO4217 code for example 'EUR' for euro. When a currency is used in multiple
  815. regions, these regions are separated with a whitespace character. Use
  816. <link linkend="zend.currency.introduction">Zend_Currency</link> for simplicity</entry>
  817. </row>
  818. <row>
  819. <entry><emphasis>RegionToTerritory</emphasis></entry>
  820. <entry>Returns the regions for a given territory. The territory has to be given as
  821. ISO4217 string for example '001' for world. The regions within this territory
  822. are separated with a whitespace character</entry>
  823. </row>
  824. <row>
  825. <entry><emphasis>TerritoryToRegion</emphasis></entry>
  826. <entry>Returns the territories where a given region is located. The region has to be
  827. given in ISO3166 string for example 'AT' for austria. When a region is located in
  828. multiple territories then these territories are separated with a whitespace
  829. character</entry>
  830. </row>
  831. <row>
  832. <entry><emphasis>ScriptToLanguage</emphasis></entry>
  833. <entry>Returns the scripts which are used within a given language. The language has
  834. to be given as ISO language code for example 'en' for english. When multiple
  835. scripts are used within a language then these scripts are separated with a
  836. whitespace character</entry>
  837. </row>
  838. <row>
  839. <entry><emphasis>LanguageToScript</emphasis></entry>
  840. <entry>Returns the languages which are used within a given script. The script has to be
  841. given as ISO script code for example 'Latn' for latin. When a script is used in
  842. multiple languages then these languages are separated with a whitespace
  843. character</entry>
  844. </row>
  845. <row>
  846. <entry><emphasis>TerritoryToLanguage</emphasis></entry>
  847. <entry>Returns the territories where a given language is used. The language has
  848. to be given as ISO language code for example 'en' for english. When multiple
  849. territories exist where this language is used then these territories are
  850. separated with a whitespace character</entry>
  851. </row>
  852. <row>
  853. <entry><emphasis>LanguageToTerritory</emphasis></entry>
  854. <entry>Returns the languages which are used within a given territory. The territory
  855. has to be given as ISO3166 code for example 'IT' for italia. When a language
  856. is used in multiple territories then these territories are separated with a
  857. whitespace character</entry>
  858. </row>
  859. <row>
  860. <entry><emphasis>TimezoneToWindows</emphasis></entry>
  861. <entry>Returns a ISO timezone for a given windows timezone</entry>
  862. </row>
  863. <row>
  864. <entry><emphasis>WindowsToTimezone</emphasis></entry>
  865. <entry>Returns a windows timezone for a given ISO timezone</entry>
  866. </row>
  867. <row>
  868. <entry><emphasis>TerritoryToTimezone</emphasis></entry>
  869. <entry>Returns the territory for a given ISO timezone</entry>
  870. </row>
  871. <row>
  872. <entry><emphasis>TimezoneToTerritory</emphasis></entry>
  873. <entry>Returns the ISO timezone for a given territory</entry>
  874. </row>
  875. <row>
  876. <entry><emphasis>CityToTimezone</emphasis></entry>
  877. <entry>Returns the localized city for a given ISO timezone. Not for all timezones
  878. does a city translation exist</entry>
  879. </row>
  880. <row>
  881. <entry><emphasis>TimezoneToCity</emphasis></entry>
  882. <entry>Returns the ISO timezone for a given localized city name. Not for all cities
  883. does a timezone exist</entry>
  884. </row>
  885. <row>
  886. <entry><emphasis>PhoneToTerritory</emphasis></entry>
  887. <entry>Returns the telephone code for a given territory (region). The territory code
  888. has to be given as ISO3166 string for example 'AT' for austria</entry>
  889. </row>
  890. <row>
  891. <entry><emphasis>TerritoryToPhone</emphasis></entry>
  892. <entry>Returns the territory (region) where a telephone code is used. The telephone
  893. code has to be given as plain integer code for example '43' for +43. When a
  894. telephone code is used in multiple territories (regions), these territories are
  895. separated with a whitespace character</entry>
  896. </row>
  897. <row>
  898. <entry><emphasis>NumericToTerritory</emphasis></entry>
  899. <entry>Returns the 3 digit number code for a given territory (region). The territory
  900. code has to be given as ISO3166 string for example 'AT' for austria</entry>
  901. </row>
  902. <row>
  903. <entry><emphasis>TerritoryToNumeric</emphasis></entry>
  904. <entry>Returns the territory (region) for a 3 digit number code. The 3 digit number
  905. code has to be given as plain integer code for example '43'
  906. </entry>
  907. </row>
  908. <row>
  909. <entry><emphasis>Alpha3ToTerritory</emphasis></entry>
  910. <entry>Returns the 3 sign character code for a given territory (region). The territory
  911. code has to be given as ISO3166 string for example 'AT' for austria</entry>
  912. </row>
  913. <row>
  914. <entry><emphasis>TerritoryToAlpha3</emphasis></entry>
  915. <entry>Returns the territory (region) for a 3 sign character code</entry>
  916. </row>
  917. <row>
  918. <entry><emphasis>PostalToTerritory</emphasis></entry>
  919. <entry>
  920. Returns the a regex for postal codes for a given territory. The
  921. territory has to be given as ISO4217 string for example '001' for
  922. world</entry>
  923. </row>
  924. <row>
  925. <entry><emphasis>NumberingSystem</emphasis></entry>
  926. <entry>
  927. Returns a scripts with the notation for digits used within this script
  928. </entry>
  929. </row>
  930. <row>
  931. <entry><emphasis>FallbackToChar</emphasis></entry>
  932. <entry>
  933. Returns a replacement character for a often used unicode character.
  934. This can be used to replace "©" with "(C)" for example
  935. </entry>
  936. </row>
  937. <row>
  938. <entry><emphasis>CharToFallback</emphasis></entry>
  939. <entry>
  940. Returns a unicode character for a often used replacement character.
  941. This can be used to replace "(C)" with "©" for example
  942. </entry>
  943. </row>
  944. <row>
  945. <entry><emphasis>LocaleUpgrade</emphasis></entry>
  946. <entry>
  947. Returns a locale dependencies for a given language which can be used to
  948. upgrade this language to a full qualified locale
  949. </entry>
  950. </row>
  951. </tbody>
  952. </tgroup>
  953. </table>
  954. <note>
  955. <para>
  956. With Zend Framework 1.5 several old types have been renamed. This has to be done because
  957. of several new types, some misspelling and to increase the usability. See this table for
  958. a list of old to new types:
  959. </para>
  960. </note>
  961. <table id="zend.locale.getdata.table-3">
  962. <title>Differences between ZF 1.0 and ZF 1.5</title>
  963. <tgroup cols="2">
  964. <thead>
  965. <row>
  966. <entry>Old type</entry>
  967. <entry>New type</entry>
  968. </row>
  969. </thead>
  970. <tbody>
  971. <row>
  972. <entry>Country</entry>
  973. <entry>Territory (with value '2')</entry>
  974. </row>
  975. <row>
  976. <entry>Calendar</entry>
  977. <entry>Type (with value 'calendar')</entry>
  978. </row>
  979. <row>
  980. <entry>Month_Short</entry>
  981. <entry>Month (with array('gregorian', 'format', 'abbreviated')</entry>
  982. </row>
  983. <row>
  984. <entry>Month_Narrow</entry>
  985. <entry>Month (with array('gregorian', 'stand-alone', 'narrow')</entry>
  986. </row>
  987. <row>
  988. <entry>Month_Complete</entry>
  989. <entry>Months</entry>
  990. </row>
  991. <row>
  992. <entry>Day_Short</entry>
  993. <entry>Day (with array('gregorian', 'format', 'abbreviated')</entry>
  994. </row>
  995. <row>
  996. <entry>Day_Narrow</entry>
  997. <entry>Day (with array('gregorian', 'stand-alone', 'narrow')</entry>
  998. </row>
  999. <row>
  1000. <entry>DateFormat</entry>
  1001. <entry>Date</entry>
  1002. </row>
  1003. <row>
  1004. <entry>TimeFormat</entry>
  1005. <entry>Time</entry>
  1006. </row>
  1007. <row>
  1008. <entry>Timezones</entry>
  1009. <entry>CityToTimezone</entry>
  1010. </row>
  1011. <row>
  1012. <entry>Currency</entry>
  1013. <entry>NameToCurrency</entry>
  1014. </row>
  1015. <row>
  1016. <entry>Currency_Sign</entry>
  1017. <entry>CurrencySymbol</entry>
  1018. </row>
  1019. <row>
  1020. <entry>Currency_Detail</entry>
  1021. <entry>CurrencyToRegion</entry>
  1022. </row>
  1023. <row>
  1024. <entry>Territory_Detail</entry>
  1025. <entry>TerritoryToRegion</entry>
  1026. </row>
  1027. <row>
  1028. <entry>Language_Detail</entry>
  1029. <entry>LanguageToTerritory</entry>
  1030. </row>
  1031. </tbody>
  1032. </tgroup>
  1033. </table>
  1034. <para>
  1035. The example below demonstrates how to obtain the names of things in different languages.
  1036. </para>
  1037. <example id="zend.locale.getdata.example-3">
  1038. <title>getTranslationList</title>
  1039. <programlisting language="php"><![CDATA[
  1040. // prints the names of all countries in German language
  1041. print_r(Zend_Locale::getTranslationList('country', 'de'));
  1042. ]]></programlisting>
  1043. </example>
  1044. <para>
  1045. The next example shows how to find the name of a language in another language, when the two letter
  1046. iso country code is not known.
  1047. </para>
  1048. <example id="zend.locale.getdata.example-4">
  1049. <title>Converting country name in one language to another</title>
  1050. <programlisting language="php"><![CDATA[
  1051. $code2name = Zend_Locale::getLanguageTranslationList('en_US');
  1052. $name2code = array_flip($code2name);
  1053. $frenchCode = $name2code['French'];
  1054. echo Zend_Locale::getLanguageTranslation($frenchCode, 'de_AT');
  1055. // output is the German name of the French language
  1056. ]]></programlisting>
  1057. </example>
  1058. <para>
  1059. To generate a list of all languages known by <classname>Zend_Locale</classname>, with each language name shown in its own language,
  1060. try the example below in a web page. Similarly, <code>getCountryTranslationList()</code> and
  1061. <code>getCountryTranslation()</code> could be used to create a table mapping your native language names for
  1062. regions to the names of the regions shown in another language. Use a
  1063. <code>try .. catch</code> block to handle exceptions that occur when using a locale that does not exist. Not
  1064. all languages are also locales. In the example, below exceptions are ignored to prevent early termination.
  1065. </para>
  1066. <example id="zend.locale.getdata.example-6">
  1067. <title>All Languages written in their native language</title>
  1068. <programlisting language="php"><![CDATA[
  1069. $list = Zend_Locale::getLanguageTranslationList('auto');
  1070. foreach($list as $language => $content) {
  1071. try {
  1072. $output = Zend_Locale::getLanguageTranslation($language, $language);
  1073. if (is_string($output)) {
  1074. print "\n<br>[".$language."] ".$output;
  1075. }
  1076. } catch (Exception $e) {
  1077. continue;
  1078. }
  1079. }
  1080. ]]></programlisting>
  1081. </example>
  1082. </sect2>
  1083. <sect2 id="zend.locale.getquestion">
  1084. <title>Obtaining translations for "yes" and "no"</title>
  1085. <para>
  1086. Frequently, programs need to solicit a "yes" or "no" response from the user. Use <code>getQuestion()</code>
  1087. to obtain an array containing the correct word(s) or regex strings to use for prompting the user in a
  1088. particular $locale (defaults to the current object's locale). The returned array will contain the
  1089. following informations :
  1090. </para>
  1091. <itemizedlist>
  1092. <listitem>
  1093. <para>
  1094. <emphasis>yes and no</emphasis>: A generic string representation for yes
  1095. and no responses. This will contain the first and most generic response from yesarray and
  1096. noarray.
  1097. </para>
  1098. <para>
  1099. <emphasis>yesarray and noarray</emphasis>: An array with all known yes and
  1100. no responses. Several languages have more than just two responses. In general this is the
  1101. full string and its abbreviation.
  1102. </para>
  1103. <para>
  1104. <emphasis>yesexpr and noexpr</emphasis>: An generated regex which allows you
  1105. to handle user response, and search for yes or no.
  1106. </para>
  1107. </listitem>
  1108. </itemizedlist>
  1109. <para>
  1110. All of this informations are of course localized and depend on the set locale. See the following
  1111. example for the informations you can receive:
  1112. </para>
  1113. <example id="zend.locale.getquestion.example-1">
  1114. <title>getQuestion()</title>
  1115. <programlisting language="php"><![CDATA[
  1116. $locale = new Zend_Locale();
  1117. // Question strings
  1118. print_r($locale->getQuestion('de'));
  1119. - - - Output - - -
  1120. Array
  1121. (
  1122. [yes] => ja
  1123. [no] => nein
  1124. [yesarray] => Array
  1125. (
  1126. [0] => ja
  1127. [1] => j
  1128. )
  1129. [noarray] => Array
  1130. (
  1131. [0] => nein
  1132. [1] => n
  1133. )
  1134. [yesexpr] => ^([jJ][aA]?)|([jJ]?)
  1135. [noexpr] => ^([nN]([eE][iI][nN])?)|([nN]?)
  1136. )
  1137. ]]></programlisting>
  1138. </example>
  1139. <note>
  1140. <para>
  1141. Until 1.0.3 <emphasis>yesabbr</emphasis> from the underlaying locale data was also
  1142. available. Since 1.5 this information is no longer standalone available, but you will find the
  1143. information from it within <emphasis>yesarray</emphasis>.
  1144. </para>
  1145. </note>
  1146. </sect2>
  1147. <sect2 id="zend.locale.getlocalelist">
  1148. <title>Get a list of all known locales</title>
  1149. <para>
  1150. Sometimes you will want to get a list of all known locales. This can be used for several tasks
  1151. like the creation of a selectbox. For this purpose you can use the static
  1152. <code>getLocaleList()</code> method which will return a list of all known locales.
  1153. </para>
  1154. <example id="zend.locale.getlocalelist.example-1">
  1155. <title>getLocaleList()</title>
  1156. <programlisting language="php"><![CDATA[
  1157. $localelist = Zend_Locale::getLocaleList();
  1158. ]]></programlisting>
  1159. </example>
  1160. <note>
  1161. <para>
  1162. Note that the locales are returned as key of the array you will receive. The value is always
  1163. a boolean true.
  1164. </para>
  1165. </note>
  1166. </sect2>
  1167. <sect2 id="zend.locale.detection">
  1168. <title>Detecting locales</title>
  1169. <para>
  1170. When you want to detect if a given input, regardless of its source, is a locale you should use
  1171. the static <code>isLocale()</code> method. The first parameter of this method is the string which
  1172. you want to check.
  1173. </para>
  1174. <example id="zend.locale.detection.example-1">
  1175. <title>Simple locale detection</title>
  1176. <programlisting language="php"><![CDATA[
  1177. $input = 'to_RU';
  1178. if (Zend_Locale::isLocale($input)) {
  1179. print "'{$input}' is a locale";
  1180. } else {
  1181. print "Sorry... the given input is no locale";
  1182. }
  1183. ]]></programlisting>
  1184. </example>
  1185. <para>
  1186. As you can see, the output of this method is always a boolean. There is only one reason you could
  1187. get an exception when calling this method. When your system does not provide any locale and
  1188. Zend Framework is not able to detect it automatically. Normally this shows that there is a problem
  1189. with your OS in combination with PHP's <code>setlocale()</code>.
  1190. </para>
  1191. <para>
  1192. You should also note that any given locale string will automatically be degraded if the region
  1193. part does not exist for this locale. In our previous example the language <code>'to'</code> does not
  1194. exist in the region <code>'RU'</code>, but you will still get true returned as <classname>Zend_Locale</classname> can
  1195. work with the given input.
  1196. </para>
  1197. <para>
  1198. Still it's sometimes usefull to prevent this automatic degrading, and this is where the second
  1199. parameter of <code>isLocale()</code> comes in place. The <code>strict</code> parameter defaults to
  1200. <constant>FALSE</constant> and can be used to prevent degrading when set to <constant>TRUE</constant>.
  1201. </para>
  1202. <example id="zend.locale.detection.example-2">
  1203. <title>Strict locale detection</title>
  1204. <programlisting language="php"><![CDATA[
  1205. $input = 'to_RU';
  1206. if (Zend_Locale::isLocale($input, true)) {
  1207. print "'{$input}' is a locale";
  1208. } else {
  1209. print "Sorry... the given input is no locale";
  1210. }
  1211. ]]></programlisting>
  1212. </example>
  1213. <para>
  1214. Now that you are able to detect if a given string is a locale you could add locale aware behaviour
  1215. to your own classes. But you will soon detect that this will always leads to the same 15 lines of
  1216. code. Something like the following example:
  1217. </para>
  1218. <example id="zend.locale.detection.example-3">
  1219. <title>Implement locale aware behaviour</title>
  1220. <programlisting language="php"><![CDATA[
  1221. if ($locale === null) {
  1222. $locale = new Zend_Locale();
  1223. }
  1224. if (!Zend_Locale::isLocale($locale, true, false)) {
  1225. if (!Zend_Locale::isLocale($locale, false, false)) {
  1226. throw new Zend_Locale_Exception(
  1227. "The locale '$locale' is no known locale");
  1228. }
  1229. $locale = new Zend_Locale($locale);
  1230. }
  1231. if ($locale instanceof Zend_Locale) {
  1232. $locale = $locale->toString();
  1233. }
  1234. ]]></programlisting>
  1235. </example>
  1236. <para>
  1237. With Zend Framework 1.8 we added a static <code>findLocale()</code> method which returns you a locale
  1238. string which you can work with. It processes the following tasks:
  1239. </para>
  1240. <itemizedlist>
  1241. <listitem>
  1242. <para>
  1243. Detects if a given string is a locale
  1244. </para>
  1245. </listitem>
  1246. <listitem>
  1247. <para>
  1248. Degrades the locale if it does not exist in the given region
  1249. </para>
  1250. </listitem>
  1251. <listitem>
  1252. <para>
  1253. Returns a previous set application wide locale if no input is given
  1254. </para>
  1255. </listitem>
  1256. <listitem>
  1257. <para>
  1258. Detects the locale from browser when the previous detections failed
  1259. </para>
  1260. </listitem>
  1261. <listitem>
  1262. <para>
  1263. Detects the locale from environment when the previous detections failed
  1264. </para>
  1265. </listitem>
  1266. <listitem>
  1267. <para>
  1268. Detects the locale from framework when the previous detections failed
  1269. </para>
  1270. </listitem>
  1271. <listitem>
  1272. <para>
  1273. Returns always a string which represents the found locale.
  1274. </para>
  1275. </listitem>
  1276. </itemizedlist>
  1277. <para>
  1278. The following example shows how these checks and the above code can be simplified with one single call:
  1279. </para>
  1280. <example id="zend.locale.detection.example-4">
  1281. <title>Locale aware behaviour as with ZF 1.8</title>
  1282. <programlisting language="php"><![CDATA[
  1283. $locale = Zend_Locale::findLocale($inputstring);
  1284. ]]></programlisting>
  1285. </example>
  1286. </sect2>
  1287. </sect1>
  1288. <!--
  1289. vim:se ts=4 sw=4 et:
  1290. -->