Zend_Translate allows you use internally
Zend_Cache to fasten the loading of translation sources. This
comes very handy if you use many translation sources or extensive source formats like
XML based files.
To use caching you will just have to give a cache object to the
Zend_Translate::setCache() method. It takes a instance of
Zend_Cache as only parameter. Also if you use any adapter direct
you can use the setCache() method. For convenience there are
also the static methods getCache(),
hasCache(), clearCache() and
removeCache().
<?php
$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();
Note
You must set the cache before you use or initiate
any adapter or instance of Zend_Translate. Otherwise your
translation source will not be cached until you add a new source with the
addTranslation() method.
When the attached cache supports tagging you can set a own tag string by using the
option tag. This allows you do delete only the cache from this
single instance of Zend_Translate. When you are not using this
option the default tag Zend_Translate is used.
Using the option tag you must give the used tag to
clearCache() to declare which tag you want to delete.
<?php
$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');




