Zend_Locale-Functions.xml 76 KB

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