Zend_Locale-Functions.xml 73 KB

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