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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.translate.adapter">
<title>Adapters for Zend_Translate</title>
<para>
<classname>Zend_Translate</classname> can handle different adapters for translation.
Each adapter has its own advantages and disadvantages.
Below is a comprehensive list of all supported adapters for
translation source files.
</para>
<table id="zend.translate.adapter.table">
<title>Adapters for Zend_Translate</title>
<tgroup cols="3">
<thead>
<row>
<entry>Adapter</entry>
<entry>Description</entry>
<entry>Usage</entry>
</row>
</thead>
<tbody>
<row>
<entry>Array</entry>
<entry>Use <acronym>PHP</acronym> arrays</entry>
<entry>Small pages; simplest usage; only for programmers</entry>
</row>
<row>
<entry>Csv</entry>
<entry>Use comma separated (*.csv/*.txt) files</entry>
<entry>
Simple text file format; fast; possible problems with unicode characters
</entry>
</row>
<row>
<entry>Gettext</entry>
<entry>Use binary gettext (*.mo) files</entry>
<entry>GNU standard for linux; thread-safe; needs tools for translation</entry>
</row>
<row>
<entry>Ini</entry>
<entry>Use simple <acronym>INI</acronym> (*.ini) files</entry>
<entry>
Simple text file format; fast; possible problems with unicode characters
</entry>
</row>
<row>
<entry>Tbx</entry>
<entry>Use termbase exchange (*.tbx/*.xml) files</entry>
<entry>
Industry standard for inter application terminology strings;
<acronym>XML</acronym> format
</entry>
</row>
<row>
<entry>Tmx</entry>
<entry>Use tmx (*.tmx/*.xml) files</entry>
<entry>
Industry standard for inter application translation; <acronym>XML</acronym>
format; human readable
</entry>
</row>
<row>
<entry>Qt</entry>
<entry>Use qt linguist (*.ts) files</entry>
<entry>
Cross platform application framework; <acronym>XML</acronym> format; human
readable
</entry>
</row>
<row>
<entry>Xliff</entry>
<entry>Use xliff (*.xliff/*.xml) files</entry>
<entry>
A simpler format as <constant>TMX</constant> but related to it;
<acronym>XML</acronym> format; human readable
</entry>
</row>
<row>
<entry>XmlTm</entry>
<entry>Use xmltm (*.xml) files</entry>
<entry>
Industry standard for <acronym>XML</acronym> document translation memory;
<acronym>XML</acronym> format; human readable
</entry>
</row>
<row>
<entry>Others</entry>
<entry>*.sql</entry>
<entry>Different other adapters may be implemented in the future</entry>
</row>
</tbody>
</tgroup>
</table>
<sect2 id="zend.translate.adapter.decision">
<title>How to decide which translation adapter to use</title>
<para>
You should decide which Adapter you want to use for
<classname>Zend_Translate</classname>. Frequently, external criteria such as a project
requirement or a customer requirement determines this for you, but if you are in
the position to do this yourself, the following hints may simplify
your decision.
</para>
<note>
<para>
When deciding your adapter you should also be aware of the used
encoding. Even if Zend Framework declares UTF-8 as default
encoding you will sometimes be in the need of other encoding.
<classname>Zend_Translate</classname> will not change any encoding which is defined
within the source file which means that if your Gettext source
is build upon ISO-8859-1 it will also return strings in this encoding
without converting them. There is only one restriction:
</para>
<para>
When you use a <acronym>XML</acronym> based source format like TMX or XLIFF you must
define the encoding within the <acronym>XML</acronym> files header because
<acronym>XML</acronym> files without defined encoding will be treated as UTF-8 by
any <acronym>XML</acronym> parser by default. You should also be aware that actually
the encoding of <acronym>XML</acronym> files is limited to the encodings supported
by <acronym>PHP</acronym> which are UTF-8, ISO-8859-1 and US-ASCII.
</para>
</note>
<sect3 id="zend.translate.adapter.array">
<title>Zend_Translate_Adapter_Array</title>
<para>
The Array Adapter is the Adapter which is simplest to use for
programmers.
But when you have numerous translation strings or many
languages you should think about another Adapter.
For example, if you have 5000 translation strings,
the Array Adapter is possibly not the best choice for you.
</para>
<para>
You should only use this Adapter for small sites with a handful
of languages, and if you or your programmer team creates the
translations yourselves.
</para>
</sect3>
<sect3 id="zend.translate.adapter.csv">
<title>Zend_Translate_Adapter_Csv</title>
<para>
The Csv Adapter is the Adapter which is simplest to use for
customers.
CSV files are readable by standard text editors, but
text editors often do not support utf8 character sets.
</para>
<para>
You should only use this Adapter if your customer wants to do
translations himself.
</para>
<note>
<para>
Beware that the Csv Adapter has problems when your Csv files are encoded
differently than the locale setting of your environment. This is due to a Bug of
<acronym>PHP</acronym> itself which will not be fixed before
<acronym>PHP</acronym> 6.0 (http://bugs.php.net/bug.php?id=38471). So you should
be aware that the Csv Adapter due to <acronym>PHP</acronym> restrictions is not
locale aware.
</para>
</note>
</sect3>
<sect3 id="zend.translate.adapter.gettext">
<title>Zend_Translate_Adapter_Gettext</title>
<para>
The Gettext Adapter is the Adapter which is used most
frequently. Gettext is a translation source format which was
introduced by GNU, and is now used worldwide.
It is not human readable, but there are several freeware tools
(for instance, <ulink url="http://sourceforge.net/projects/poedit/">POEdit</ulink>),
which are very helpful. The <classname>Zend_Translate</classname> Gettext Adapter is
not implemented using <acronym>PHP</acronym>'s gettext extension.
You can use the Gettext Adapter even if you do not have
the <acronym>PHP</acronym> gettext extension installed.
Also the Adapter is thread-safe and the <acronym>PHP</acronym> gettext extension
is currently not thread-safe.
</para>
<para>
Most people will use this adapter.
With the available tools, professional translation is
very simple. But gettext data are is stored in a
machine-readable format, which is not readable without tools.
</para>
</sect3>
<sect3 id="zend.translate.adapter.ini">
<title>Zend_Translate_Adapter_Ini</title>
<para>
The Ini Adapter is a very simple Adapter which can even be used
directly by customers.
<acronym>INI</acronym> files are readable by standard text editors, but
text editors often do not support utf8 character sets.
</para>
<para>
You should only use this Adapter when your customer wants to do translations
himself. Do not use this adapter as generic translation source.
</para>
<warning>
<title>Regression in PHP 5.3</title>
<para>
Prior to <acronym>PHP</acronym> 5.3, <methodname>parse_ini_file()</methodname>
and <methodname>parse_ini_string()</methodname> handled non-ASCII characters
within <acronym>INI</acronym> option keys worked without an issue. However,
starting with <acronym>PHP</acronym> 5.3, any such keys will now be silently
dropped in the returned array from either function. If you had keys utilizing
UTF-8 or Latin-1 characters, you may find your translations no longer work when
using the <acronym>INI</acronym> adapter. If this is the case, we recommend
utilizing a different adapter.
</para>
</warning>
</sect3>
<sect3 id="zend.translate.adapter.tbx">
<title>Zend_Translate_Adapter_Tbx</title>
<para>
The Tbx Adapter is an Adapter which will be used by customers
which already use the TBX format for their internal translation
system. Tbx is no standard translation format but more a collection
of already translated and pre translated source strings. When you
use this adapter you have to be sure that all your needed source
string are translated.
TBX is a <acronym>XML</acronym> file based format and a completely new format.
<acronym>XML</acronym> files are human-readable, but the parsing is not as fast
as with gettext files.
</para>
<para>
This adapter is perfect for companies when pre translated
source files already exist.
The files are human readable and system-independent.
</para>
</sect3>
<sect3 id="zend.translate.adapter.tmx">
<title>Zend_Translate_Adapter_Tmx</title>
<para>
The Tmx Adapter is the Adapter which will be used by most
customers which have multiple systems which use the same
translation source, or when the translation source must be
system-independent.
TMX is a <acronym>XML</acronym> file based format, which is announced to be the
next industry standard.
<acronym>XML</acronym> files are human-readable, but the parsing is not as fast
as with gettext files.
</para>
<para>
Most medium to large companies use this adapter.
The files are human readable and system-independent.
</para>
</sect3>
<sect3 id="zend.translate.adapter.qt">
<title>Zend_Translate_Adapter_Qt</title>
<para>
The Qt Adapter is for all customers which have TS files as their
translation source which are made by QtLinguist.
QT is a <acronym>XML</acronym> file based format.
<acronym>XML</acronym> files are human-readable, but the parsing is not as fast
as with gettext files.
</para>
<para>
Several big players have build software upon the QT framework.
The files are human readable and system-independent.
</para>
</sect3>
<sect3 id="zend.translate.adapter.xliff">
<title>Zend_Translate_Adapter_Xliff</title>
<para>
The Xliff Adapter is the Adapter which will be used by most customers which
want to have <acronym>XML</acronym> files but do not have tools for TMX.
XLIFF is a <acronym>XML</acronym> file based format, which is related to TMX but
simpler as it does not support all possibilities of it.
<acronym>XML</acronym> files are human-readable, but the parsing is not as fast
as with gettext files.
</para>
<para>
Most medium companies use this adapter.
The files are human readable and system-independent.
</para>
</sect3>
<sect3 id="zend.translate.adapter.xmltm">
<title>Zend_Translate_Adapter_XmlTm</title>
<para>
The XmlTm Adapter is the Adapter which will be used by customers
which do their layout themself. XmlTm is a format which allows the
complete <acronym>HTML</acronym> source to be included in the translation source, so
the translation is coupled with the layout.
XLIFF is a <acronym>XML</acronym> file based format, which is related to XLIFF but
its not as simple to read.
</para>
<para>
This adapter should only be used when source files already exist.
The files are human readable and system-independent.
</para>
</sect3>
</sect2>
<sect2 id="zend.translate.adapter.selfwritten">
<title>Integrate self written Adapters</title>
<para>
<classname>Zend_Translate</classname> allows you to integrate and use self written
Adapter classes. They can be used like the standard Adapter classes which
are already included within <classname>Zend_Translate</classname>.
</para>
<para>
Any adapter class you want to use with <classname>Zend_Translate</classname> must be a
subclass of <classname>Zend_Translate_Adapter</classname>.
<classname>Zend_Translate_Adapter</classname> is an abstract class which already defines
all what is needed for translation. What has to be done by you, is the definition of the
reader for translation datas.
</para>
<para>
The usage of the prefix "Zend" should be limited to Zend Framework.
If you extend <classname>Zend_Translate</classname> with your own adapter, you should
name it like "Company_Translate_Adapter_MyFormat". The following code shows an
example of how a self written adapter class could be implemented:
</para>
<programlisting language="php"><![CDATA[
try {
$translate = new Zend_Translate(
array(
'adapter' => 'Company_Translate_Adapter_MyFormat',
'content' => '/path/to/translate.xx',
'locale' => 'en',
'myoption' => 'myvalue'
)
);
} catch (Exception $e) {
// File not found, no adapter class...
// General failure
}
]]></programlisting>
</sect2>
<sect2 id="zend.translate.adapter.caching">
<title>Speedup all Adapters</title>
<para>
<classname>Zend_Translate</classname> allows you use internally
<classname>Zend_Cache</classname> to fasten the loading of translation sources. This
comes very handy if you use many translation sources or extensive source formats like
<acronym>XML</acronym> based files.
</para>
<para>
To use caching you will just have to give a cache object to the
<methodname>Zend_Translate::setCache()</methodname> method. It takes a instance of
<classname>Zend_Cache</classname> as only parameter. Also if you use any adapter direct
you can use the <methodname>setCache()</methodname> method. For convenience there are
also the static methods <methodname>getCache()</methodname>,
<methodname>hasCache()</methodname>, <methodname>clearCache()</methodname> and
<methodname>removeCache()</methodname>.
</para>
<programlisting language="php"><![CDATA[
$cache = Zend_Cache::factory('Core',
'File',
$frontendOptions,
$backendOptions);
Zend_Translate::setCache($cache);
$translate = new Zend_Translate(
array(
'adapter' => 'gettext',
'content' => '/path/to/translate.mo',
'locale' => 'en'
)
);
// to clear the cache somewhere later in your code
Zend_Translate::clearCache();
]]></programlisting>
<note>
<para>
You must set the cache <emphasis>before</emphasis> you use or initiate
any adapter or instance of <classname>Zend_Translate</classname>. Otherwise your
translation source will not be cached until you add a new source with the
<methodname>addTranslation()</methodname> method.
</para>
</note>
<para>
When the attached cache supports tagging you can set a own tag string by using the
option <property>tag</property>. This allows you do delete only the cache from this
single instance of <classname>Zend_Translate</classname>. When you are not using this
option the default tag <classname>Zend_Translate</classname> is used.
</para>
<para>
Using the option <property>tag</property> you must give the used tag to
<methodname>clearCache()</methodname> to declare which tag you want to delete.
</para>
<programlisting language="php"><![CDATA[
$cache = Zend_Cache::factory('Core',
'File',
$frontendOptions,
$backendOptions);
Zend_Translate::setCache($cache);
$translate = new Zend_Translate(
array(
'adapter' => 'gettext',
'content' => '/path/to/translate.mo',
'locale' => 'en',
'tag' => 'MyTag'
)
);
// somewhere later in your code
Zend_Translate::clearCache('MyTag');
]]></programlisting>
</sect2>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->
|