1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="performance.localization">
4 <title>Internationalization (i18n) and Localization (l10n)</title>
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
14 <sect2 id="performance.localization.translationadapter">
15 <title>Which translation adapter should I use?</title>
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
25 <sect3 id="performance.localization.translationadapter.fastest">
26 <title>Use non-XML translation adapters for greatest speed</title>
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:
39 <emphasis>Array</emphasis>: this is the fastest, as it is, by
40 definition, parsed into a native <acronym>PHP</acronym> format immediately
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.
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.
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>.
76 If high performance is one of your concerns, we suggest
77 utilizing one of the above adapters.
82 <sect2 id="performance.localization.cache">
83 <title>How can I make translation and localization even faster?</title>
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
92 <sect3 id="performance.localization.cache.usage">
93 <title>Use translation and localization caches</title>
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
105 You can read about caching of translation and localization
106 strings in the following locations:
113 linkend="zend.translate.adapter.caching"><classname>Zend_Translate</classname>
114 adapter caching</link>
120 <link linkend="zend.locale.cache"><classname>Zend_Locale</classname>