Zeta Components Manual :: Docs For Class ezcTranslationCacheBackend
TranslationCacheTiein::ezcTranslationCacheBackend
Class ezcTranslationCacheBackend
Translation backend that reads translation data from a cache.
This class is a backend implementation for the Translation system. This specific one uses the Cache Component to store and serve cached translation data.
Example that uses both the ezcCacheStorageFileArray and ezcTranslationCacheBackend classes:
- <?php
 - // Create a cache object with content
 - $expected = array(
 - 'Knoop ID: %node_id Zichtbaar: %visibility',
 - );
 - $cacheObj->store( 'nl-nl/contentstructuremenu/show_content_structure', $expected );
 - // Use the cache backend
 - echo $translation->getTranslation( 'Node ID: %node_id Visibility: %visibility',
 - array( 'node_id' => 42, 'visibility' => 'yes' ) );
 - ?>
 
Example that stores a whole translation file into a cache by using ezcTranslationContextRead interface that is implemented by the ezcTranslationTsBackend and the ezcTranslationContextWrite interface that is implemented by this class:
- <?php
 - // Settings
 - $locale = 'nb-no';
 - // Setup the cache object
 - // Initialize the writer
 - // Initialize the reader
 - $reader->initReader( $locale );
 - // Process the data
 - $contexts = array();
 - foreach ( $reader as $contextName => $contextData )
 - {
 - }
 - // Deinitialize the writer and reader
 - $reader->deinitReader();
 - ?>
 
Source for this file: /TranslationCacheTiein/src/backends/cache_backend.php
Implements interfaces:
| Version: | //autogentag// | 
Method Summary
| public ezcTranslationCacheBackend | 
            
              __construct(
                                                                                    $cacheObject
                                                 )
            
            Constructs a new ezcTranslationCacheBackend that will store data to $cacheObject.            | 
        
| public void | 
            
              deinitWriter(
               )
            
            Deinitializes the writer.            | 
        
| public array(ezcTranslationData) | 
            
              getContext(
                                                                                    $locale
                                                    ,                                     $context
                                                 )
            
            Returns a array containing the translation map for the specified  $locale and $context.            | 
        
| public void | 
            
              initWriter(
                                                                                    $locale
                                                 )
            
            Initializes the writer to write to the locale $locale.            | 
        
| public void | 
            
              setOptions(
                                                                                    $configurationData
                                                 )
            
            Sets configuration data            | 
        
| public void | 
            
              storeContext(
                                                                                    $context
                                                    ,                                     $data
                                                 )
            
            Stores a context.            | 
        
Methods
__construct
Constructs a new ezcTranslationCacheBackend that will store data to $cacheObject.
Parameters:
| Name | Type | Description | 
|---|---|---|
$cacheObject | 
              ezcCacheStorageFileArray | 
deinitWriter
Deinitializes the writer.
This method should be called after the last context was written to cleanup resources.
Exceptions:
| Type | Description | 
|---|---|
ezcTranslationWriterNotInitializedException | 
              when the writer is not initialized with initWriter(). | 
getContext
Returns a array containing the translation map for the specified $locale and $context.
It uses the $tsLocationPath and $tsFilenameFormat properties to locate the file, unless caching is enabled. If a cache object is available it will be used to retrieve the information from the cache.
Parameters:
| Name | Type | Description | 
|---|---|---|
$locale | 
              string | |
$context | 
              string | 
Exceptions:
| Type | Description | 
|---|---|
ezcTranslationContextNotAvailableException | 
              if the context is not available. | 
initWriter
Initializes the writer to write to the locale $locale.
Before starting to writer contexts to the writer, you should call this method to initialize it.
Parameters:
| Name | Type | Description | 
|---|---|---|
$locale | 
              string | $return void | 
setOptions
Sets configuration data
This backend accepts no settings at all, and will always throw an ezcBaseSettingNotFoundException for every setting that is contained in the $configurationData.
Parameters:
| Name | Type | Description | 
|---|---|---|
$configurationData | 
              array | 
Exceptions:
| Type | Description | 
|---|---|
ezcBaseSettingNotFoundException | 
              if an unknown setting is passed. | 
storeContext
Stores a context.
This method stores the context that it received to the backend specified storage place.
Parameters:
| Name | Type | Description | 
|---|---|---|
$context | 
              string | The context's name | 
$data | 
              array(ezcTranslationData) | The context's translation map | 
Exceptions:
| Type | Description | 
|---|---|
ezcTranslationWriterNotInitializedException | 
              when the writer is not initialized with initWriter(). |