[GENERIC] Zend_Translate:
[zend.git] / documentation / manual / en / ref / performance-localization.xml
blobf7f858491b4fcd84ab28a65b73f5f6df3610f7d9
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- Reviewed: no -->
3 <sect1 id="performance.localization">
4     <title>Internationalization (i18n) and Localization (l10n)</title>
6     <para>
7         Internationalizing and localizing a site are fantastic ways to expand
8         your audience and ensure that all visitors can get to the information
9         they need. However, it often comes with a performance penalty. Below
10         are some strategies you can employ to reduce the overhead of i18n and
11         l10n.
12     </para>
14     <sect2 id="performance.localization.translationadapter">
15         <title>Which translation adapter should I use?</title>
17         <para>
18             Not all translation adapters are made equal. Some have more
19             features than others, and some perform better than others.
20             Additionally, you may have business requirements that force you to
21             use a particular adapter. However, if you have a choice, which
22             adapters are fastest?
23         </para>
25         <sect3 id="performance.localization.translationadapter.fastest">
26             <title>Use non-XML translation adapters for greatest speed</title>
28             <para>
29                 Zend Framework ships with a variety of translation adapters.
30                 Fully half of them utilize an <acronym>XML</acronym> format, incurring memory and
31                 performance overhead. Fortunately, there are several adapters
32                 that utilize other formats that can be parsed much more
33                 quickly. In order of speed, from fastest to slowest, they are:
34             </para>
36             <itemizedlist>
37                 <listitem>
38                     <para>
39                         <emphasis>Array</emphasis>: this is the fastest, as it is, by
40                         definition, parsed into a native <acronym>PHP</acronym> format immediately
41                         on inclusion.
42                     </para>
43                 </listitem>
45                 <listitem>
46                     <para>
47                         <emphasis><acronym>CSV</acronym></emphasis>: uses
48                         <methodname>fgetcsv()</methodname> to parse a <acronym>CSV</acronym> file
49                         and transform it into a native <acronym>PHP</acronym> format.
50                     </para>
51                 </listitem>
53                 <listitem>
54                     <para>
55                         <emphasis><acronym>INI</acronym></emphasis>: uses
56                         <methodname>parse_ini_file()</methodname> to parse an <acronym>INI</acronym>
57                         file and transform it into a native <acronym>PHP</acronym> format. This and
58                         the <acronym>CSV</acronym> adapter are roughly equivalent performance-wise.
59                     </para>
60                 </listitem>
62                 <listitem>
63                     <para>
64                         <emphasis>Gettext</emphasis>: The gettext adapter from Zend Framework
65                         does <emphasis>not</emphasis> use the gettext
66                         extension as it is not thread safe and does not allow
67                         specifying more than one locale per server. As a result, it
68                         is slower than using the gettext extension directly, but,
69                         because the gettext format is binary, it's faster to parse
70                         than <acronym>XML</acronym>.
71                     </para>
72                 </listitem>
73             </itemizedlist>
75             <para>
76                 If high performance is one of your concerns, we suggest
77                 utilizing one of the above adapters.
78             </para>
79         </sect3>
80     </sect2>
82     <sect2 id="performance.localization.cache">
83         <title>How can I make translation and localization even faster?</title>
85         <para>
86             Maybe, for business reasons, you're limited to an <acronym>XML</acronym>-based
87             translation adapter. Or perhaps you'd like to speed things up even
88             more. Or perhaps you want to make l10n operations faster. How can
89             you do this?
90         </para>
92         <sect3 id="performance.localization.cache.usage">
93             <title>Use translation and localization caches</title>
95             <para>
96                 Both <classname>Zend_Translate</classname> and <classname>Zend_Locale</classname>
97                 implement caching functionality that can greatly affect
98                 performance. In the case of each, the major bottleneck is
99                 typically reading the files, not the actual lookups; using a
100                 cache eliminates the need to read the translation and/or
101                 localization files.
102             </para>
104             <para>
105                 You can read about caching of translation and localization
106                 strings in the following locations:
107             </para>
109             <itemizedlist>
110                 <listitem>
111                     <para>
112                         <link
113                             linkend="zend.translate.adapter.caching"><classname>Zend_Translate</classname>
114                             adapter caching</link>
115                     </para>
116                 </listitem>
118                 <listitem>
119                     <para>
120                         <link linkend="zend.locale.cache"><classname>Zend_Locale</classname>
121                             caching</link>
122                     </para>
123                 </listitem>
124             </itemizedlist>
125         </sect3>
126     </sect2>
127 </sect1>
128 <!--
129 vim:se ts=4 sw=4 et: