Zend_Application-AvailableResources-Locale.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 20077 -->
  3. <!-- Reviewed: no -->
  4. <sect2 id="zend.application.available-resources.locale">
  5. <title>Zend_Application_Resource_Locale</title>
  6. <para>
  7. <classname>Zend_Application_Resource_Locale</classname> can be used to
  8. set an application-wide locale which is then used in all classes and components
  9. which work with localization or internationalization.
  10. </para>
  11. <para>
  12. There are basically three usecases for the Locale Resource Plugin. Each of them
  13. should be used depending on the applications need.
  14. </para>
  15. <sect3 id="zend.application.available-resources.locale.auto">
  16. <title>Autodetect the locale to use</title>
  17. <para>
  18. Without specifying any options for
  19. <classname>Zend_Application_Resource_Locale</classname>,
  20. <classname>Zend_Locale</classname> will detect the locale, which your application will
  21. use, automatically.
  22. </para>
  23. <para>
  24. This detection works because your client sends the wished language within his
  25. <acronym>HTTP</acronym> request. Normally the clients browser sends the languages he
  26. wants to see, and <classname>Zend_Locale</classname> uses this information for
  27. detection.
  28. </para>
  29. <para>
  30. But there are 2 problems with this approach:
  31. </para>
  32. <itemizedlist>
  33. <listitem>
  34. <para>
  35. The browser could be setup to send no language
  36. </para>
  37. </listitem>
  38. <listitem>
  39. <para>
  40. The user could have manually set a locale which does not exist
  41. </para>
  42. </listitem>
  43. </itemizedlist>
  44. <para>
  45. In both cases <classname>Zend_Locale</classname> will fallback to other mechanism to
  46. detect the locale:
  47. </para>
  48. <itemizedlist>
  49. <listitem>
  50. <para>
  51. When a locale has been set which does not exist,
  52. <classname>Zend_Locale</classname> tries to downgrade this string.
  53. </para>
  54. <para>
  55. When, for example, <emphasis>en_ZZ</emphasis> is set it will automatically
  56. be degraded to <emphasis>en</emphasis>. In this case <emphasis>en</emphasis>
  57. will be used as locale for your application.
  58. </para>
  59. </listitem>
  60. <listitem>
  61. <para>
  62. When the locale could also not be detected by downgrading, the locale of your
  63. environment (web server) will be used. Most available environments from
  64. Web Hosters use <emphasis>en</emphasis> as locale.
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. When the systems locale could not be detected <classname>Zend_Locale</classname>
  70. will use it's default locale, which is set to <emphasis>en</emphasis> per
  71. default.
  72. </para>
  73. </listitem>
  74. </itemizedlist>
  75. <para>
  76. For more informations about locale detection take a look into <link
  77. linkend="zend.locale.selection.automatic">this chapter on Zend_Locale's automatic
  78. detection</link>.
  79. </para>
  80. </sect3>
  81. <sect3 id="zend.application.available-resources.locale.fallback">
  82. <title>Autodetect the locale and adding a own fallback</title>
  83. <para>
  84. The above autodetection could lead to problems when the locale could not be detected and
  85. you want to have another default locale than <emphasis>en</emphasis>. To prevent this,
  86. <classname>Zend_Application_Resource_Locale</classname> allows you to set a own locale
  87. which will be used in the case that the locale could not be detected.
  88. </para>
  89. <example id="zend.application.available-resources.locale.configExampleDetectAndFallback">
  90. <title>Autodetect locale and setting a fallback</title>
  91. <para>
  92. The following snippet shows how to set a own default locale which will be used when
  93. the client does not send a locale himself.
  94. </para>
  95. <programlisting language="ini"><![CDATA[
  96. ; Try to determine automatically first,
  97. ; if unsuccessful, use nl_NL as fallback.
  98. resources.locale.default = "nl_NL"
  99. ]]></programlisting>
  100. </example>
  101. </sect3>
  102. <sect3 id="zend.application.available-resources.locale.forcing">
  103. <title>Forcing a specific locale to use</title>
  104. <para>
  105. Sometimes it is useful to define a single locale which has to be used. This can be done
  106. by using the <property>force</property> option.
  107. </para>
  108. <para>
  109. In this case this single locale will be used and the automatic detection is turned
  110. off.
  111. </para>
  112. <example id="zend.application.available-resources.locale.configExampleFallbackOnly">
  113. <title>Defining a single locale to use</title>
  114. <para>
  115. The following snippet shows how to set a single locale for your entire application.
  116. </para>
  117. <programlisting language="ini"><![CDATA[
  118. ; No matter what, the nl_NL locale will be used.
  119. resources.locale.default = "nl_NL"
  120. resources.locale.force = true
  121. ]]></programlisting>
  122. </example>
  123. </sect3>
  124. </sect2>