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