## Apache 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:

1. <?php
2. // Create a cache object with content
3. $cacheObj=new ezcCacheStorageFileArray ('ezcTranslationCacheBackendTest');
5. $expected=array(
6. new ezcTranslationData ('Node ID: %node_id Visibility: %visibility',
7. 'Knoop ID: %node_id Zichtbaar: %visibility',
8. false, ezcTranslationData ::TRANSLATED)
9. );
10. $cacheObj->store('nl-nl/contentstructuremenu/show_content_structure',$expected);
12. // Use the cache backend
13. $backend=new ezcTranslationCacheBackend ($cacheObj);
14. $context=$backend-> getContext ('nl-nl','contentstructuremenu/show_content_structure');
15. $translation=new ezcTranslation ($context);
16. echo$translation->getTranslation('Node ID: %node_id Visibility: %visibility',
17. array('node_id'=>42,'visibility'=>'yes') );
18. ?>

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:

1. <?php
2. // Settings
3. $locale='nb-no';
5. // Setup the cache object
6. $cacheObj=new ezcCacheStorageFileArray ('ezcTranslationCacheBackendTest');
8. // Initialize the writer
9. $writer=new ezcTranslationCacheBackend ($cacheObj);
10. $writer-> initWriter ($locale);
12. // Initialize the reader
13. $reader=new ezcTranslationTsBackend ("translations");
14. $reader-> setOptions (array('format'=>'[LOCALE].xml') );
15. $reader->initReader($locale);
17. // Process the data
18. $contexts=array();
19. foreach($readeras$contextName=>$contextData)
20. {
21. $writer-> storeContext ($contextName,$contextData);
22. }
24. // Deinitialize the writer and reader
25. $writer-> deinitWriter ();
26. $reader->deinitReader();
27. ?>

Source for this file: /TranslationCacheTiein/src/backends/cache_backend.php

### Implements interfaces:

- ezcTranslationBackend
- ezcTranslationContextWrite

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

ezcTranslationCacheBackend __construct( $cacheObject )

Constructs a new ezcTranslationCacheBackend that will store data to $cacheObject.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$cacheObject` | ezcCacheStorageFileArray |

#### deinitWriter

void 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

array(ezcTranslationData) getContext( string $locale , string $context )

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

void initWriter( string $locale )

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

void setOptions( array $configurationData )

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

void storeContext( string $context , $data )

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().

Documentation generated by phpDocumentor 1.4.3