Zend_Application-AvailableResources-Locale.xml 5.5 KB

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