Zend_Application-AvailableResources-Locale.xml 6.5 KB

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