1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.locale.functions">
<title>Using Zend_Locale</title>
<para>
<classname>Zend_Locale</classname> also provides localized information about locales for
each locale, including localized names for other locales, days of the week, month names,
etc.
</para>
<sect2 id="zend.locale.copying">
<title>Copying, Cloning, and Serializing Locale Objects</title>
<para>
Use <ulink url="http://php.net/language.oop5.cloning">object cloning</ulink> to
duplicate a locale object exactly and efficiently. Most locale-aware methods also accept
string representations of locales, such as the result of
<command>$locale->toString()</command>.
</para>
<example id="zend.locale.copying.example-1">
<title>clone</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale('ar');
// Save the $locale object as a serialization
$serializedLocale = $locale->serialize();
// re-create the original object
$localeObject = unserialize($serializedLocale);
// Obtain a string identification of the locale
$stringLocale = $locale->toString();
// Make a cloned copy of the $local object
$copiedLocale = clone $locale;
print "copied: ", $copiedLocale->toString();
// PHP automatically calls toString() via __toString()
print "copied: ", $copiedLocale;
]]></programlisting>
</example>
</sect2>
<sect2 id="zend.locale.equals">
<title>Equality</title>
<para>
<classname>Zend_Locale</classname> also provides a convenience function to compare two
locales. All locale-aware classes should provide a similar equality check.
</para>
<example id="zend.locale.equals.example-1">
<title>Check for equal locales</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale();
$mylocale = new Zend_Locale('en_US');
// Check if locales are equal
if ($locale->equals($mylocale)) {
print "Locales are equal";
}
]]></programlisting>
</example>
</sect2>
<sect2 id="zend.locale.getdefault">
<title>Default locales</title>
<para>
The method <methodname>getDefault()</methodname> returns an array of relevant locales
using information from the user's web browser (if available), information from the
environment of the host server, and Zend Framework settings. As with the constructor
for <classname>Zend_Locale</classname>, the first parameter selects a preference of
which information to consider <link
linkend="zend.locale.selection">(<constant>BROWSER</constant>,
<constant>ENVIRONMENT</constant>, or <constant>FRAMEWORK</constant></link> first.
The second parameter toggles between returning all matching locales or only the
first or best match. Locale-aware components normally use only the first locale. A
quality rating is included, when available.
</para>
<example id="zend.locale.getdefault.example-1">
<title>Get default locales</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale();
// Return all default locales
$found = $locale->getDefault();
print_r($found);
// Return only browser locales
$found2 = $locale->getDefault(Zend_Locale::BROWSER,TRUE);
print_r($found2);
]]></programlisting>
</example>
<para>
To obtain only the default locales relevant to the <link
linkend="zend.locale.selection"><constant>BROWSER</constant>,
<constant>ENVIRONMENT</constant>, or <constant>FRAMEWORK</constant></link>, use
the corresponding method:
<itemizedlist>
<listitem>
<para>
<methodname>getEnvironment()</methodname>
</para>
</listitem>
<listitem>
<para>
<methodname>getBrowser()</methodname>
</para>
</listitem>
<listitem>
<para>
<methodname>getLocale()</methodname>
</para>
</listitem>
</itemizedlist>
</para>
</sect2>
<sect2 id="zend.locale.setlocale">
<title>Set a new locale</title>
<para>
A new locale can be set with the function <methodname>setLocale()</methodname>. This
function takes a locale string as parameter. If no locale is given, a locale is
<link linkend="zend.locale.selection">automatically selected</link>.
</para>
<example id="zend.locale.setlocale.example-1">
<title>setLocale</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale();
// Actual locale
print $locale->toString();
// new locale
$locale->setLocale('aa_DJ');
print $locale->toString();
]]></programlisting>
</example>
</sect2>
<sect2 id="zend.locale.getlocale">
<title>Getting the language and region</title>
<para>
Use <methodname>getLanguage()</methodname> to obtain a string containing the two
character language code from the string locale identifier. Use
<methodname>getRegion()</methodname> to obtain a string containing the two character
region code from the string locale identifier.
</para>
<example id="zend.locale.getlocale.example-1">
<title>getLanguage and getRegion</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale();
// if locale is 'de_AT' then 'de' will be returned as language
print $locale->getLanguage();
// if locale is 'de_AT' then 'AT' will be returned as region
print $locale->getRegion();
]]></programlisting>
</example>
</sect2>
<sect2 id="zend.locale.getlocaletoterritory">
<title>Get the locale by giving a territory</title>
<para>
When you only have the territory or country then it's also possible to get a locale
from that information. You can manually search if there is a locale for this territory
by using <methodname>getLocaleToTerritory()</methodname>. This method returns a
locale for the given territory or <constant>NULL</constant> when there was has no locale
been found.
</para>
<example id="zend.locale.getlocaletoterritory.example-1">
<title>getLocaleToTerritory</title>
<programlisting language="php"><![CDATA[
$locale = Zend_Locale::getLocaleToTerritory('US');
// returns 'en_US'
]]></programlisting>
</example>
<note>
<title>Uppercase territories</title>
<para>
When you know that you are using a territory, then you should uppercase it.
Otherwise you could get an in your eyes false locale in return when you use other
methods. For example: When you give "om" then
<methodname>getLocaleToTerritory()</methodname> returns you "ar_OM" as it knows that
you mean a territory. But all other methods will return "om", as it's also a
language.
</para>
<para>
So when you know that the given string is a territory, eighter use
<methodname>getLocaleToTerritory()</methodname> yourself before creating a locale,
or uppercase the input.
</para>
</note>
</sect2>
<sect2 id="zend.locale.getdata">
<title>Obtaining localized strings</title>
<para>
<methodname>getTranslationList()</methodname> gives you access to localized information
of several types. These information are useful if you want to display localized data to
a customer without the need of translating it. They are already available for your
usage.
</para>
<para>
The requested list of information is always returned as named array. If you want to give
more than one value to a explicit type where you wish to receive values from, you have
to give an array instead of multiple values.
</para>
<example id="zend.locale.getdata.example-1">
<title>getTranslationList</title>
<programlisting language="php"><![CDATA[
$list = Zend_Locale::getTranslationList('language', 'de_AT');
print_r ($list);
// example key -> value pairs...
// [de] -> Deutsch
// [en] -> Englisch
// use one of the returned key as value for the getTranslation() method
// of another language
print Zend_Locale::getTranslation('de', 'language', 'zh');
// returns the translation for the language 'de' in chinese
]]></programlisting>
</example>
<para>
You can receive this information for all languages. But not all information is
completely available for all languages. Some of these types are also available through
an own function for simplicity. See this list for detailed information.
</para>
<table id="zend.locale.getdata.table-1">
<title>
Details for getTranslationList($type = null, $locale = null, $value = null)
</title>
<tgroup cols="2">
<thead>
<row>
<entry>Type</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><emphasis>Language</emphasis></entry>
<entry>
Returns a localized list of all languages. The language part of the
locale is returned as key and the translation as value
</entry>
</row>
<row>
<entry><emphasis>Script</emphasis></entry>
<entry>
Returns a localized list of all scripts. The script is returned as key
and the translation as value
</entry>
</row>
<row>
<entry><emphasis>Territory</emphasis></entry>
<entry>
Returns a localized list of all territories. This contains countries,
continents and territories. To get only territories and continents use
'1' as value. To get only countries use '2' as value. The country part
of the locale is used as key where applicable. In the other case the
official <acronym>ISO</acronym> code for this territory is used. The
translated territory is returned as value. When you omit the value you
will get a list with both.
</entry>
</row>
<row>
<entry><emphasis>Variant</emphasis></entry>
<entry>
Returns a localized list of known variants of scripts. The variant is
returned as key and the translation as value
</entry>
</row>
<row>
<entry><emphasis>Key</emphasis></entry>
<entry>
Returns a localized list of known keys. This keys are generic values
used in translation. These are normally calendar, collation and
currency. The key is returned as array key and the translation as value
</entry>
</row>
<row>
<entry><emphasis>Type</emphasis></entry>
<entry>
Returns a localized list of known types of keys. These are variants of
types of calendar representations and types of collations. When you use
'collation' as value you will get all types of collations returned. When
you use 'calendar' as value you will get all types of calendars
returned. When you omit the value you will get a list all both returned.
The type is used as key and the translation as value
</entry>
</row>
<row>
<entry><emphasis>Layout</emphasis></entry>
<entry>
Returns a list of rules which describes how to format special text parts
</entry>
</row>
<row>
<entry><emphasis>Characters</emphasis></entry>
<entry>Returns a list of allowed characters within this locale</entry>
</row>
<row>
<entry><emphasis>Delimiters</emphasis></entry>
<entry>Returns a list of allowed quoting characters for this locale</entry>
</row>
<row>
<entry><emphasis>Measurement</emphasis></entry>
<entry>
Returns a list of known measurement values. This list is depreciated
</entry>
</row>
<row>
<entry><emphasis>Months</emphasis></entry>
<entry>
Returns a list of all month representations within this locale. There
are several different representations which are all returned as sub
array. If you omit the value you will get a list of all months from the
'gregorian' calendar returned. You can give any known calendar as value
to get a list of months from this calendar returned. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>Month</emphasis></entry>
<entry>
Returns a localized list of all month names for this locale. If you omit
the value you will get the normally used gregorian full name of the
months where each month number is used as key and the translated month
is returned as value. You can get the months for different calendars and
formats if you give an array as value. The first array entry has to be
the calendar, the second the used context and the third the width to
return. Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Days</emphasis></entry>
<entry>
Returns a list of all day representations within this locale. There are
several different representations which are all returned as sub array.
If you omit the value you will get a list of all days from the
'gregorian' calendar returned. You can give any known calendar as value
to get a list of days from this calendar returned. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>Day</emphasis></entry>
<entry>
Returns a localized list of all day names for this locale. If you omit
the value you will get the normally used gregorian full name of the days
where the english day abbreviation is used as key and the translated day
is returned as value. You can get the days for different calendars and
formats if you give an array as value. The first array entry has to be
the calendar, the second the used context and the third the width to
return. Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Week</emphasis></entry>
<entry>
Returns a list of values used for proper week calculations within a
locale. Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Quarters</emphasis></entry>
<entry>
Returns a list of all quarter representations within this locale. There
are several different representations which are all returned as sub
array. If you omit the value you will get a list of all quarters from
the 'gregorian' calendar returned. You can give any known calendar as
value to get a list of quarters from this calendar returned
</entry>
</row>
<row>
<entry><emphasis>Quarter</emphasis></entry>
<entry>
Returns a localized list of all quarter names for this locale. If you
omit the value you will get the normally used gregorian full name of the
quarters where each quarter number is used as key and the translated
quarter is returned as value. You can get the quarters for different
calendars and formats if you give an array as value. The first array
entry has to be the calendar, the second the used context and the third
the width to return
</entry>
</row>
<row>
<entry><emphasis>Eras</emphasis></entry>
<entry>
Returns a list of all era representations within this locale. If you
omit the value you will get a list of all eras from the 'gregorian'
calendar returned. You can give any known calendar as value to get a
list of eras from this calendar returned
</entry>
</row>
<row>
<entry><emphasis>Era</emphasis></entry>
<entry>
Returns a localized list of all era names for this locale. If you omit
the value you will get the normally used gregorian full name of the eras
where each era number is used as key and the translated era is returned
as value. You can get the eras for different calendars and formats if
you give an array as value. The first array entry has to be the calendar
and the second the width to return
</entry>
</row>
<row>
<entry><emphasis>Date</emphasis></entry>
<entry>
Returns a localized list of all date formats for this locale. The name
of the dateformat is used as key and the format itself as value.If you
omit the value you will get the date formats for the gregorian calendar
returned. You can get the date formats for different calendars if you
give the wished calendar as string. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>Time</emphasis></entry>
<entry>
Returns a localized list of all time formats for this locale. The name
of the timeformat is used as key and the format itself as value. If you
omit the value you will get the time formats for the gregorian calendar
returned. You can get the time formats for different calendars if you
give the wished calendar as string. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>DateTime</emphasis></entry>
<entry>
Returns a localized list of all known date-time formats for this locale.
The name of the date-time format is used as key and the format itself as
value. If you omit the value you will get the date-time formats for the
gregorian calendar returned. You can get the date-time formats for
different calendars if you give the wished calendar as string. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>DateItem</emphasis></entry>
<entry>
Returns a list of default formats for given date or time items
</entry>
</row>
<row>
<entry><emphasis>DateInterval</emphasis></entry>
<entry>
Returns a list of date or time formats which are used when you want to
display intervals. The list is a multidimentional array where the first
dimension is the interval format, and the second dimension is the token
with the greatest difference.
</entry>
</row>
<row>
<entry><emphasis>Field</emphasis></entry>
<entry>
Returns a localized list of date fields which can be used to display
calendars or date strings like 'month' or 'year' in a wished language.
If you omit the value you will get this list for the gregorian calendar
returned. You can get the list for different calendars if you give the
wished calendar as string
</entry>
</row>
<row>
<entry><emphasis>Relative</emphasis></entry>
<entry>
Returns a localized list of relative dates which can be used to display
textual relative dates like 'yesterday' or 'tomorrow' in a wished
language. If you omit the value you will get this list for the gregorian
calendar returned. You can get the list for different calendars if you
give the wished calendar as string
</entry>
</row>
<row>
<entry><emphasis>Symbols</emphasis></entry>
<entry>
Returns a localized list of characters used for number representations
</entry>
</row>
<row>
<entry><emphasis>NameToCurrency</emphasis></entry>
<entry>
Returns a localized list of names for currencies. The currency is used
as key and the translated name as value. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencyToName</emphasis></entry>
<entry>
Returns a list of currencies for localized names. The translated name is
used as key and the currency as value. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencySymbol</emphasis></entry>
<entry>
Returns a list of known localized currency symbols for currencies. The
currency is used as key and the symbol as value. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Question</emphasis></entry>
<entry>
Returns a list of localized strings for acceptance ('yes') and
negation ('no'). Use <link
linkend="zend.locale.getquestion">Zend_Locale's getQuestion
method</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencyFraction</emphasis></entry>
<entry>
Returns a list of fractions for currency values. The currency is used as
key and the fraction as integer value. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencyRounding</emphasis></entry>
<entry>
Returns a list of how to round which currency. The currency is used as
key and the rounding as integer value. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencyToRegion</emphasis></entry>
<entry>
Returns a list of currencies which are known to be used within a region.
The <constant>ISO3166</constant> value ('region') is used as array key
and the <constant>ISO4217</constant> value ('currency') as array value.
Use <link linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>RegionToCurrency</emphasis></entry>
<entry>
Returns a list of regions where a currency is used . The
<constant>ISO4217</constant> value ('currency') is used as array key and
the <constant>ISO3166</constant> value ('region') as array value. When a
currency is used in several regions these regions are separated with a
whitespace. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>RegionToTerritory</emphasis></entry>
<entry>
Returns a list of territories with the countries or sub territories
which are included within that territory. The <acronym>ISO</acronym>
territory code ('territory') is used as array key and the
<constant>ISO3166</constant> value ('region') as array value. When a
territory contains several regions these regions are separated with a
whitespace
</entry>
</row>
<row>
<entry><emphasis>TerritoryToRegion</emphasis></entry>
<entry>
Returns a list of regions and the territories where these regions are
located. The <constant>ISO3166</constant> code ('region') is used as
array key and the <acronym>ISO</acronym> territory code ('territory') as
array value. When a region is located in several territories these
territories are separated with a whitespace
</entry>
</row>
<row>
<entry><emphasis>ScriptToLanguage</emphasis></entry>
<entry>
Returns a list of scripts which are used within a language. The language
code is used as array key and the script code as array value. When a
language contains several scripts these scripts are separated with a
whitespace
</entry>
</row>
<row>
<entry><emphasis>LanguageToScript</emphasis></entry>
<entry>
Returns a list of languages which are using a script. The script code
is used as array key and the language code as array value. When a script
is used in several languages these languages are separated with a
whitespace
</entry>
</row>
<row>
<entry><emphasis>TerritoryToLanguage</emphasis></entry>
<entry>
Returns a list of languages and the countries where they are spoken. The
language is used as array key and the country code as array value. When
a language is used in several countries these countries are separated
with a whitespace
</entry>
</row>
<row>
<entry><emphasis>LanguageToTerritory</emphasis></entry>
<entry>
Returns a list of countries and the languages which are spoken within
them. The country code is used as array key and the language code
as array value. When several languages are spoken within a territory
then these languages are separated with a whitespace
</entry>
</row>
<row>
<entry><emphasis>TimezoneToWindows</emphasis></entry>
<entry>
Returns a list of windows timezones and the related
<acronym>ISO</acronym> timezone. The windows timezone is used as array
key and the <acronym>ISO</acronym> timezone as array value
</entry>
</row>
<row>
<entry><emphasis>WindowsToTimezone</emphasis></entry>
<entry>
Returns a list of <acronym>ISO</acronym> timezones and the related
windows timezone. The <acronym>ISO</acronym> timezone is used as array
key and the windows timezone as array value
</entry>
</row>
<row>
<entry><emphasis>TerritoryToTimezone</emphasis></entry>
<entry>
Returns a list of regions or territories and the related
<acronym>ISO</acronym> timezone. The <acronym>ISO</acronym> timezone is
used as array key and the territory code as array value
</entry>
</row>
<row>
<entry><emphasis>TimezoneToTerritory</emphasis></entry>
<entry>
Returns a list of timezones and the related region or territory code.
The region or territory code is used as array key and the
<acronym>ISO</acronym> timezone as array value
</entry>
</row>
<row>
<entry><emphasis>CityToTimezone</emphasis></entry>
<entry>
Returns a localized list of cities which can be used as translation for
a related timezone. Not for all timezones is a translation available,
but for a user is the real city written in his languages more accurate
than the <acronym>ISO</acronym> name of this timezone. The
<acronym>ISO</acronym> timezone is used as array key and the translated
city as array value
</entry>
</row>
<row>
<entry><emphasis>TimezoneToCity</emphasis></entry>
<entry>
Returns a list of timezones for localized city names. The localized city
is used as array key and the <acronym>ISO</acronym> timezone name as
array value
</entry>
</row>
<row>
<entry><emphasis>PhoneToTerritory</emphasis></entry>
<entry>
Returns a list of phone codes which are known to be used within a
territory. The territory (region) is used as array key and the telephone
code as array value
</entry>
</row>
<row>
<entry><emphasis>TerritoryToPhone</emphasis></entry>
<entry>
Returns a list of territories where a phone is used . The phone code
is used as array key and the territory (region) as array value. When a
phone code is used in several territories these territories are
separated with a whitespace
</entry>
</row>
<row>
<entry><emphasis>NumericToTerritory</emphasis></entry>
<entry>
Returns a list of 3 digit number codes for territories.
The territory (region) is used as array key and the 3 digit number code
as array value
</entry>
</row>
<row>
<entry><emphasis>TerritoryToNumeric</emphasis></entry>
<entry>
Returns a list of territories with their 3 digit number code. The 3
digit number code is used as array key and the territory (region) as
array value
</entry>
</row>
<row>
<entry><emphasis>Alpha3ToTerritory</emphasis></entry>
<entry>
Returns a list of 3 sign character codes for territories.
The territory (region) is used as array key and the 3 sign character
code as array value
</entry>
</row>
<row>
<entry><emphasis>TerritoryToAlpha3</emphasis></entry>
<entry>
Returns a list of territories with their 3 sign character code. The 3
sign character code is used as array key and the territory (region) as
array value
</entry>
</row>
<row>
<entry><emphasis>PostalToTerritory</emphasis></entry>
<entry>
Returns a list of territories with a regex for postal codes which are
included within that territory. The <acronym>ISO</acronym> territory
code ('territory') is used as array key and the regex as array value.
</entry>
</row>
<row>
<entry><emphasis>NumberingSystem</emphasis></entry>
<entry>
Returns a list of scripts with the notation for digits used within the
script
</entry>
</row>
<row>
<entry><emphasis>FallbackToChar</emphasis></entry>
<entry>
Returns a list of replacement characters for often used unicode
characters. This can be used to replace "©" with "(C)" for example
</entry>
</row>
<row>
<entry><emphasis>CharToFallback</emphasis></entry>
<entry>
Returns a list of unicode characters for often used replacement
characters. This can be used to replace "(C)" with "©" for example
</entry>
</row>
<row>
<entry><emphasis>LocaleUpgrade</emphasis></entry>
<entry>
Returns a list of locale dependencies which can be used to upgrade a
language to a full qualified locale
</entry>
</row>
<row>
<entry><emphasis>Unit</emphasis></entry>
<entry>
Returns a list of localized calendar units. This can be used to
translate the strings "day", "month" and so on automatically
</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
If you are in need of a single translated value, you can use the
<methodname>getTranslation()</methodname> method. It always returns a string but it
accepts some different types than the <methodname>getTranslationList()</methodname>
method. Also value is the same as before with one difference. You have to give the
detail you want to get returned as additional value.
</para>
<note>
<para>
Because you have almost always give a value as detail this parameter has to be given
as first parameter. This differs from the
<methodname>getTranslationList()</methodname> method.
</para>
</note>
<para>
See the following table for detailed information:
</para>
<table id="zend.locale.getdata.table-2">
<title>Details for getTranslation($value = null, $type = null, $locale = null)</title>
<tgroup cols="2">
<thead>
<row>
<entry>Type</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><emphasis>Language</emphasis></entry>
<entry>
Returns a translation for a language. To select the wished translation
you must give the language code as value
</entry>
</row>
<row>
<entry><emphasis>Script</emphasis></entry>
<entry>
Returns a translation for a script. To select the wished translation you
must give the script code as value
</entry>
</row>
<row>
<entry>
<emphasis>Territory</emphasis> or <emphasis>Country</emphasis>
</entry>
<entry>
Returns a translation for a territory. This can be countries, continents
and territories. To select the wished variant you must give the
territory code as value
</entry>
</row>
<row>
<entry><emphasis>Variant</emphasis></entry>
<entry>
Returns a translation for a script variant. To select the wished variant
you must give the variant code as value
</entry>
</row>
<row>
<entry><emphasis>Key</emphasis></entry>
<entry>
Returns translation for a known keys. This keys are generic values used
in translation. These are normally calendar, collation and currency. To
select the wished key you must give the key code as value
</entry>
</row>
<row>
<entry><emphasis>DefaultCalendar</emphasis></entry>
<entry>
Returns the default calendar for the given locale. For most locales this
will be 'gregorian'. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>MonthContext</emphasis></entry>
<entry>
Returns the default context for months which is used within the given
calendar. If you omit the value the 'gregorian' calendar will be used.
Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>DefaultMonth</emphasis></entry>
<entry>
Returns the default format for months which is used within the given
calendar. If you omit the value the 'gregorian' calendar will be used.
Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Month</emphasis></entry>
<entry>
Returns a translation for a month. You have to give the number of the
month as integer value. It has to be between 1 and 12. If you want to
receive data for other calendars, contexts or formats, then you must
give an array instead of an integer with the expected values. The array
has to look like this: <command>array( 'calendar', 'context', 'format',
'month number')</command>. If you give only an integer then the
default values are the 'gregorian' calendar, the context 'format' and
the format 'wide'. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>DayContext</emphasis></entry>
<entry>
Returns the default context for ´days which is used within the given
calendar. If you omit the value the 'gregorian' calendar will be used.
Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>DefaultDay</emphasis></entry>
<entry>
Returns the default format for days which is used within the given
calendar. If you omit the value the 'gregorian' calendar will be used.
Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Day</emphasis></entry>
<entry>
Returns a translation for a day. You have to give the english
abbreviation of the day as string value ('sun', 'mon', etc.). If you
want to receive data for other calendars, contexts or format, then you
must give an array instead of an integer with the expected values. The
array has to look like this: <methodname>array('calendar', 'context',
'format', 'day abbreviation')</methodname>. If you give only an
string then the default values are the 'gregorian' calendar, the context
'format' and the format 'wide'. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>Quarter</emphasis></entry>
<entry>
Returns a translation for a quarter. You have to give the number of the
quarter as integer and it has to be between 1 and 4. If you want to
receive data for other calendars, contexts or formats, then you must
give an array instead of an integer with the expected values. The array
has to look like this: <methodname>array('calendar', 'context',
'format', 'quarter number')</methodname>. If you give only an
string then the default values are the 'gregorian' calendar,
the context 'format' and the format 'wide'
</entry>
</row>
<row>
<entry><emphasis>Am</emphasis></entry>
<entry>
Returns translation for 'AM' in the expected locale. If you want to
receive data for other calendars provide a string with the expected
calendar. If you omit the value then the 'gregorian' calendar will be
used. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>Pm</emphasis></entry>
<entry>
Returns translation for 'PM' in the expected locale. If you want to
receive data for other calendars provide a string with the expected
calendar. If you omit the value then the 'gregorian' calendar will be
used. Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Era</emphasis></entry>
<entry>
Returns a translation for an era within a locale. You have to give the
era number as string or integer. If you want to receive data for other
calendars or formats, then you must give an array instead of the era
number with the expected values. The array has to look like this:
<methodname>array('calendar', 'format', 'era number')</methodname>. If
you give only a string then the default values are the 'gregorian'
calendar and the 'abbr' format
</entry>
</row>
<row>
<entry><emphasis>DefaultDate</emphasis></entry>
<entry>
Returns the default date format which is used within the given
calendar. If you omit the value the 'gregorian' calendar will be used.
Use <link linkend="zend.date.introduction">Zend_Date</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Date</emphasis></entry>
<entry>
Returns the date format for a given calendar or format within a locale.
If you omit the value then the 'gregorian' calendar will be used with
the 'medium' format. If you give a string then the 'gregorian' calendar
will be used with the given format. Or you can also give an array which
will have to look like this: <methodname>array('calendar',
'format')</methodname>. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>DefaultTime</emphasis></entry>
<entry>
Returns the default time format which is used within the given calendar.
If you omit the value the 'gregorian' calendar will be used. Use
<link linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>Time</emphasis></entry>
<entry>
Returns the time format for a given calendar or format within a locale.
If you omit the value then the 'gregorian' calendar will be used with
the 'medium' format. If you give a string then the 'gregorian' calendar
will be used with the given format. Or you can also give an array which
will have to look like this:
<methodname>array('calendar', 'format')</methodname>. Use <link
linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>DateTime</emphasis></entry>
<entry>
Returns the datetime format for the given locale which indicates how to
display date with times in the same string within the given calendar. If
you omit the value the 'gregorian' calendar will be used. Use
<link linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>DateItem</emphasis></entry>
<entry>Returns the default format for a given date or time item</entry>
</row>
<row>
<entry><emphasis>DateInterval</emphasis></entry>
<entry>
Returns the interval format for a given date or time format. The first
value is the calendar format, normally 'gregorian'. The second value is
the interval format and the third value the token with the greatest
difference. For example: array('gregorian', 'yMMMM', 'y') returns the
interval format for the date format 'yMMMM' where 'y' has the greatest
difference.
</entry>
</row>
<row>
<entry><emphasis>Field</emphasis></entry>
<entry>
Returns a translated date field which can be used to display calendars
or date strings like 'month' or 'year' in a wished language. You must
give the field which has to be returned as string. In this case the
'gregorian' calendar will be used. You can get the field for other
calendar formats if you give an array which has to look like this:
<methodname>array('calendar', 'date field')</methodname>
</entry>
</row>
<row>
<entry><emphasis>Relative</emphasis></entry>
<entry>
Returns a translated date which is relative to today which can include
date strings like 'yesterday' or 'tomorrow' in a wished language. You
have to give the number of days relative to tomorrow to receive the
expected string. Yesterday would be '-1', tomorrow '1' and so on. This
will use the 'gregorian' calendar. if you want to get relative dates for
other calendars you will have to give an array which has to look like
this: <methodname>array('calendar', 'relative days')</methodname>. Use
<link linkend="zend.date.introduction">Zend_Date</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>DecimalNumber</emphasis></entry>
<entry>
Returns the format for decimal numbers within a given locale. Use <link
linkend="zend.locale.parsing">Zend_Locale_Format</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>ScientificNumber</emphasis></entry>
<entry>
Returns the format for scientific numbers within a given locale
</entry>
</row>
<row>
<entry><emphasis>PercentNumber</emphasis></entry>
<entry>
Returns the format for percentage numbers within a given locale
</entry>
</row>
<row>
<entry><emphasis>CurrencyNumber</emphasis></entry>
<entry>
Returns the format for displaying currency numbers within a given
locale. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>NameToCurrency</emphasis></entry>
<entry>
Returns the translated name for a given currency. The currency has to be
given in <acronym>ISO</acronym> format which is for example 'EUR' for
the currency 'euro'. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencyToName</emphasis></entry>
<entry>
Returns a currency for a given localized name. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencySymbol</emphasis></entry>
<entry>
Returns the used symbol for a currency within a given locale. Not for
all currencies exists a symbol. Use
<link linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>Question</emphasis></entry>
<entry>
Returns a localized string for acceptance ('yes') and negation ('no').
You have to give either 'yes' or 'no' as value to receive the expected
string. Use <link linkend="zend.locale.getquestion">Zend_Locale's
getQuestion method</link> for simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencyFraction</emphasis></entry>
<entry>
Returns the fraction to use for a given currency. You must give the
currency as <acronym>ISO</acronym> value. Use <link
linkend="zend.currency.introduction">Zend_Currency</link>
for simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencyRounding</emphasis></entry>
<entry>
Returns how to round a given currency. You must give the currency as
<acronym>ISO</acronym> value. If you omit the currency then the
'DEFAULT' rounding will be returned. Use <link
linkend="zend.currency.introduction">Zend_Currency</link>
for simplicity
</entry>
</row>
<row>
<entry><emphasis>CurrencyToRegion</emphasis></entry>
<entry>
Returns the currency for a given region. The region code has to be given
as <constant>ISO3166</constant> string for example 'AT' for austria. Use
<link linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>RegionToCurrency</emphasis></entry>
<entry>
Returns the regions where a currency is used. The currency has to be
given as <constant>ISO4217</constant> code for example 'EUR' for euro.
When a currency is used in multiple regions, these regions are separated
with a whitespace character. Use <link
linkend="zend.currency.introduction">Zend_Currency</link> for
simplicity
</entry>
</row>
<row>
<entry><emphasis>RegionToTerritory</emphasis></entry>
<entry>
Returns the regions for a given territory. The territory has to be given
as <constant>ISO4217</constant> string for example '001' for world. The
regions within this territory are separated with a whitespace character
</entry>
</row>
<row>
<entry><emphasis>TerritoryToRegion</emphasis></entry>
<entry>
Returns the territories where a given region is located. The region has
to be given in <constant>ISO3166</constant> string for example 'AT' for
austria. When a region is located in multiple territories then these
territories are separated with a whitespace character
</entry>
</row>
<row>
<entry><emphasis>ScriptToLanguage</emphasis></entry>
<entry>
Returns the scripts which are used within a given language. The language
has to be given as <acronym>ISO</acronym> language code for example 'en'
for english. When multiple scripts are used within a language then these
scripts are separated with a whitespace character
</entry>
</row>
<row>
<entry><emphasis>LanguageToScript</emphasis></entry>
<entry>
Returns the languages which are used within a given script. The script
has to be given as <acronym>ISO</acronym> script code for example 'Latn'
for latin. When a script is used in multiple languages then these
languages are separated with a whitespace character
</entry>
</row>
<row>
<entry><emphasis>TerritoryToLanguage</emphasis></entry>
<entry>
Returns the territory where a given language is used. The language has
to be given as <acronym>ISO</acronym> language code for example 'en' for
english. When the given language is spoken within multiple territories
then these territories are separated with a whitespace character
</entry>
</row>
<row>
<entry><emphasis>LanguageToTerritory</emphasis></entry>
<entry>
Returns the language which is spoken within a given territory. The
territory has to be given as <constant>ISO3166</constant> code for
example 'IT' for italia. When multiple languages are spoken within the
given territory then these languages are separated with a whitespace
character
</entry>
</row>
<row>
<entry><emphasis>TimezoneToWindows</emphasis></entry>
<entry>
Returns a <acronym>ISO</acronym> timezone for a given windows timezone
</entry>
</row>
<row>
<entry><emphasis>WindowsToTimezone</emphasis></entry>
<entry>
Returns a windows timezone for a given <acronym>ISO</acronym> timezone
</entry>
</row>
<row>
<entry><emphasis>TerritoryToTimezone</emphasis></entry>
<entry>
Returns the territory for a given <acronym>ISO</acronym> timezone
</entry>
</row>
<row>
<entry><emphasis>TimezoneToTerritory</emphasis></entry>
<entry>
Returns the <acronym>ISO</acronym> timezone for a given territory
</entry>
</row>
<row>
<entry><emphasis>CityToTimezone</emphasis></entry>
<entry>
Returns the localized city for a given <acronym>ISO</acronym> timezone.
Not for all timezones does a city translation exist
</entry>
</row>
<row>
<entry><emphasis>TimezoneToCity</emphasis></entry>
<entry>
Returns the <acronym>ISO</acronym> timezone for a given localized city
name. Not for all cities does a timezone exist
</entry>
</row>
<row>
<entry><emphasis>PhoneToTerritory</emphasis></entry>
<entry>
Returns the telephone code for a given territory (region). The territory
code has to be given as <constant>ISO3166</constant> string for example
'AT' for austria
</entry>
</row>
<row>
<entry><emphasis>TerritoryToPhone</emphasis></entry>
<entry>
Returns the territory (region) where a telephone code is used. The
telephone code has to be given as plain integer code for example '43'
for +43. When a telephone code is used in multiple territories
(regions), these territories are separated with a whitespace character
</entry>
</row>
<row>
<entry><emphasis>NumericToTerritory</emphasis></entry>
<entry>
Returns the 3 digit number code for a given territory (region). The
territory code has to be given as <constant>ISO3166</constant> string
for example 'AT' for austria
</entry>
</row>
<row>
<entry><emphasis>TerritoryToNumeric</emphasis></entry>
<entry>
Returns the territory (region) for a 3 digit number code. The 3 digit
number code has to be given as plain integer code for example '43'
</entry>
</row>
<row>
<entry><emphasis>Alpha3ToTerritory</emphasis></entry>
<entry>
Returns the 3 sign character code for a given territory (region). The
territory code has to be given as <constant>ISO3166</constant> string
for example 'AT' for austria
</entry>
</row>
<row>
<entry><emphasis>TerritoryToAlpha3</emphasis></entry>
<entry>Returns the territory (region) for a 3 sign character code</entry>
</row>
<row>
<entry><emphasis>PostalToTerritory</emphasis></entry>
<entry>
Returns the a regex for postal codes for a given territory. The
territory has to be given as <constant>ISO4217</constant> string for
example '001' for world
</entry>
</row>
<row>
<entry><emphasis>NumberingSystem</emphasis></entry>
<entry>
Returns a scripts with the notation for digits used within this script
</entry>
</row>
<row>
<entry><emphasis>FallbackToChar</emphasis></entry>
<entry>
Returns a replacement character for a often used unicode character.
This can be used to replace "©" with "(C)" for example
</entry>
</row>
<row>
<entry><emphasis>CharToFallback</emphasis></entry>
<entry>
Returns a unicode character for a often used replacement character.
This can be used to replace "(C)" with "©" for example
</entry>
</row>
<row>
<entry><emphasis>LocaleUpgrade</emphasis></entry>
<entry>
Returns a locale dependencies for a given language which can be used to
upgrade this language to a full qualified locale
</entry>
</row>
<row>
<entry><emphasis>Unit</emphasis></entry>
<entry>
Returns a localized calendar unit. This can be used to translate
the strings "day", "month" and so on automatically. The first parameter
has to be the type, and the second parameter has to be the count
</entry>
</row>
</tbody>
</tgroup>
</table>
<note>
<para>
With Zend Framework 1.5 several old types have been renamed. This has to be done
because of several new types, some misspelling and to increase the usability. See
this table for a list of old to new types:
</para>
</note>
<table id="zend.locale.getdata.table-3">
<title>Differences between Zend Framework 1.0 and 1.5</title>
<tgroup cols="2">
<thead>
<row>
<entry>Old type</entry>
<entry>New type</entry>
</row>
</thead>
<tbody>
<row>
<entry>Country</entry>
<entry>Territory (with value '2')</entry>
</row>
<row>
<entry>Calendar</entry>
<entry>Type (with value 'calendar')</entry>
</row>
<row>
<entry>Month_Short</entry>
<entry>Month (with array('gregorian', 'format', 'abbreviated')</entry>
</row>
<row>
<entry>Month_Narrow</entry>
<entry>Month (with array('gregorian', 'stand-alone', 'narrow')</entry>
</row>
<row>
<entry>Month_Complete</entry>
<entry>Months</entry>
</row>
<row>
<entry>Day_Short</entry>
<entry>Day (with array('gregorian', 'format', 'abbreviated')</entry>
</row>
<row>
<entry>Day_Narrow</entry>
<entry>Day (with array('gregorian', 'stand-alone', 'narrow')</entry>
</row>
<row>
<entry>DateFormat</entry>
<entry>Date</entry>
</row>
<row>
<entry>TimeFormat</entry>
<entry>Time</entry>
</row>
<row>
<entry>Timezones</entry>
<entry>CityToTimezone</entry>
</row>
<row>
<entry>Currency</entry>
<entry>NameToCurrency</entry>
</row>
<row>
<entry>Currency_Sign</entry>
<entry>CurrencySymbol</entry>
</row>
<row>
<entry>Currency_Detail</entry>
<entry>CurrencyToRegion</entry>
</row>
<row>
<entry>Territory_Detail</entry>
<entry>TerritoryToRegion</entry>
</row>
<row>
<entry>Language_Detail</entry>
<entry>LanguageToTerritory</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
The example below demonstrates how to obtain the names of things in different languages.
</para>
<example id="zend.locale.getdata.example-3">
<title>getTranslationList</title>
<programlisting language="php"><![CDATA[
// prints the names of all countries in German language
print_r(Zend_Locale::getTranslationList('country', 'de'));
]]></programlisting>
</example>
<para>
The next example shows how to find the name of a language in another language, when the
two letter iso country code is not known.
</para>
<example id="zend.locale.getdata.example-4">
<title>Converting country name in one language to another</title>
<programlisting language="php"><![CDATA[
$code2name = Zend_Locale::getLanguageTranslationList('en_US');
$name2code = array_flip($code2name);
$frenchCode = $name2code['French'];
echo Zend_Locale::getLanguageTranslation($frenchCode, 'de_AT');
// output is the German name of the French language
]]></programlisting>
</example>
<para>
To generate a list of all languages known by <classname>Zend_Locale</classname>, with
each language name shown in its own language, try the example below in a web page.
Similarly, <methodname>getCountryTranslationList()</methodname> and
<methodname>getCountryTranslation()</methodname> could be used to create a table mapping
your native language names for regions to the names of the regions shown in another
language. Use a <command>try .. catch</command> block to handle exceptions that occur
when using a locale that does not exist. Not all languages are also locales. In the
example, below exceptions are ignored to prevent early termination.
</para>
<example id="zend.locale.getdata.example-6">
<title>All Languages written in their native language</title>
<programlisting language="php"><![CDATA[
$list = Zend_Locale::getLanguageTranslationList('auto');
foreach($list as $language => $content) {
try {
$output = Zend_Locale::getLanguageTranslation($language, $language);
if (is_string($output)) {
print "\n<br>[".$language."] ".$output;
}
} catch (Exception $e) {
continue;
}
}
]]></programlisting>
</example>
</sect2>
<sect2 id="zend.locale.getquestion">
<title>Obtaining translations for "yes" and "no"</title>
<para>
Frequently, programs need to solicit a "yes" or "no" response from the user. Use
<methodname>getQuestion()</methodname> to obtain an array containing the correct word(s)
or regex strings to use for prompting the user in a particular $locale (defaults to the
current object's locale). The returned array will contain the following information :
</para>
<itemizedlist>
<listitem>
<para>
<emphasis>yes and no</emphasis>: A generic string representation for yes and no
responses. This will contain the first and most generic response from yesarray
and noarray.
</para>
<para>
<emphasis>yesarray and noarray</emphasis>: An array with all known yes and
no responses. Several languages have more than just two responses. In general
this is the full string and its abbreviation.
</para>
<para>
<emphasis>yesexpr and noexpr</emphasis>: A generated regex which allows you
to handle user response, and search for yes or no.
</para>
</listitem>
</itemizedlist>
<para>
All of this information are of course localized and depend on the set locale. See the
following example for the information you can receive:
</para>
<example id="zend.locale.getquestion.example-1">
<title>getQuestion()</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale();
// Question strings
print_r($locale->getQuestion('de'));
- - - Output - - -
Array
(
[yes] => ja
[no] => nein
[yesarray] => Array
(
[0] => ja
[1] => j
)
[noarray] => Array
(
[0] => nein
[1] => n
)
[yesexpr] => ^([jJ][aA]?)|([jJ]?)
[noexpr] => ^([nN]([eE][iI][nN])?)|([nN]?)
)
]]></programlisting>
</example>
<note>
<para>
Until 1.0.3 <emphasis>yesabbr</emphasis> from the underlaying locale data was also
available. Since 1.5 this information is no longer standalone available, but you
will find the information from it within <emphasis>yesarray</emphasis>.
</para>
</note>
</sect2>
<sect2 id="zend.locale.getlocalelist">
<title>Get a list of all known locales</title>
<para>
Sometimes you will want to get a list of all known locales. This can be used for several
tasks like the creation of a selectbox. For this purpose you can use the static
<methodname>getLocaleList()</methodname> method which will return a list of all known
locales.
</para>
<example id="zend.locale.getlocalelist.example-1">
<title>getLocaleList()</title>
<programlisting language="php"><![CDATA[
$localelist = Zend_Locale::getLocaleList();
]]></programlisting>
</example>
<note>
<para>
Note that the locales are returned as key of the array you will receive. The value
is always a boolean <constant>TRUE</constant>.
</para>
</note>
</sect2>
<sect2 id="zend.locale.detection">
<title>Detecting locales</title>
<para>
When you want to detect if a given input, regardless of its source, is a locale you
should use the static <methodname>isLocale()</methodname> method. The first parameter of
this method is the string which you want to check.
</para>
<example id="zend.locale.detection.example-1">
<title>Simple locale detection</title>
<programlisting language="php"><![CDATA[
$input = 'to_RU';
if (Zend_Locale::isLocale($input)) {
print "'{$input}' is a locale";
} else {
print "Sorry... the given input is no locale";
}
]]></programlisting>
</example>
<para>
As you can see, the output of this method is always a boolean. There is only one reason
you could get an exception when calling this method. When your system does not provide
any locale and Zend Framework is not able to detect it automatically. Normally this
shows that there is a problem with your OS in combination with <acronym>PHP</acronym>'s
<methodname>setlocale()</methodname>.
</para>
<para>
You should also note that any given locale string will automatically be degraded if the
region part does not exist for this locale. In our previous example the language
'<property>to</property>' does not exist in the region '<property>RU</property>', but
you will still get <constant>TRUE</constant> returned as
<classname>Zend_Locale</classname> can work with the given input.
</para>
<para>
Still it's sometimes useful to prevent this automatic degrading, and this is where the
second parameter of <methodname>isLocale()</methodname> comes in place. The
<property>strict</property> parameter defaults to <constant>FALSE</constant> and can be
used to prevent degrading when set to <constant>TRUE</constant>.
</para>
<example id="zend.locale.detection.example-2">
<title>Strict locale detection</title>
<programlisting language="php"><![CDATA[
$input = 'to_RU';
if (Zend_Locale::isLocale($input, true)) {
print "'{$input}' is a locale";
} else {
print "Sorry... the given input is no locale";
}
]]></programlisting>
</example>
<para>
Now that you are able to detect if a given string is a locale you could add locale aware
behaviour to your own classes. But you will soon detect that this always leads to
the same 15 lines of code. Something like the following example:
</para>
<example id="zend.locale.detection.example-3">
<title>Implement locale aware behaviour</title>
<programlisting language="php"><![CDATA[
if ($locale === null) {
$locale = new Zend_Locale();
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
throw new Zend_Locale_Exception(
"The locale '$locale' is no known locale");
}
$locale = new Zend_Locale($locale);
}
if ($locale instanceof Zend_Locale) {
$locale = $locale->toString();
}
]]></programlisting>
</example>
<para>
With Zend Framework 1.8 we added a static <methodname>findLocale()</methodname> method
which returns a locale string which you can work with. It processes the following
tasks:
</para>
<itemizedlist>
<listitem>
<para>
Detects if a given string is a locale
</para>
</listitem>
<listitem>
<para>
Degrades the locale if it does not exist in the given region
</para>
</listitem>
<listitem>
<para>
Upgrades the locale when it is detected as region without language
</para>
</listitem>
<listitem>
<para>
Returns a previous set application wide locale if no input is given
</para>
</listitem>
<listitem>
<para>
Detects the locale from browser when the previous detections failed
</para>
</listitem>
<listitem>
<para>
Detects the locale from environment when the previous detections failed
</para>
</listitem>
<listitem>
<para>
Detects the locale from framework when the previous detections failed
</para>
</listitem>
<listitem>
<para>
Returns always a string which represents the found locale.
</para>
</listitem>
</itemizedlist>
<para>
The following example shows how these checks and the above code can be simplified with
one single call:
</para>
<example id="zend.locale.detection.example-4">
<title>Locale aware behaviour as with Zend Framework 1.8</title>
<programlisting language="php"><![CDATA[
$locale = Zend_Locale::findLocale($inputstring);
]]></programlisting>
</example>
</sect2>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->
|