Author: Derick Rethans
Date: 2006-01-27 12:49:06 +0100 (Fri, 27 Jan 2006)
New Revision: 2050

Log:
- Added caching part to the Translation tutorial.
- Added minimal tutorial for the TranslationCacheTiein package that points to
  the Translation tutorial.

Added:
   packages/Translation/trunk/docs/translations-cache/
   packages/Translation/trunk/docs/tutorial_example_05.php
   packages/Translation/trunk/docs/tutorial_example_06.php
   packages/TranslationCacheTiein/trunk/docs/tutorial.txt
Modified:
   packages/Translation/trunk/docs/tutorial.txt


Property changes on: packages/Translation/trunk/docs/translations-cache
___________________________________________________________________
Name: svn:ignore
   + nb_NO


Modified: packages/Translation/trunk/docs/tutorial.txt
===================================================================
--- packages/Translation/trunk/docs/tutorial.txt        2006-01-27 11:47:18 UTC 
(rev 2049)
+++ packages/Translation/trunk/docs/tutorial.txt        2006-01-27 11:49:06 UTC 
(rev 2050)
@@ -86,6 +86,8 @@
 followed by the ISO3166_ country code. e.g. nb_NO for Bokmål/Norway or nl_BE
 for Dutch/Belgium.
 
+Example 1
+---------
 .. include:: tutorial_example_01.php
    :literal:
 
@@ -115,10 +117,13 @@
 identifiers (%search_string, %matches). In the following example we show how to
 use this:
 
+Example 2
+---------
+
 .. include:: tutorial_example_02.php
    :literal:
 
-The first lines are the same as in the first example. But this time we retrieve
+The first lines are the same as in `Example 1`_. But this time we retrieve
 an ezcTranslation object for the same context for two different locales (in
 line 8 and 9). In line 11 and 12 we request the translation for "Search for
 '%search_string' returned %matches matches.". This sentence has two parameters
@@ -157,6 +162,9 @@
 Filters are applied after the backend retrieved the data, but before it is 
placed
 in the internal cache of the manager. 
 
+Example 3a
+----------
+
 .. include:: tutorial_example_03.php
    :literal:
 
@@ -172,6 +180,9 @@
 text is translatable, but not yet translated. The "Leet" filter renders your
 text using Leetspeak_. Both filters are demonstrated in the following example:
 
+Example 3b
+----------
+
 .. include:: tutorial_example_03b.php
    :literal:
 
@@ -202,6 +213,9 @@
 an Iterator. The ezcTranslationTsBackend is such a class. Using this interface
 is extremely easy, as you can see in the next example:
 
+Example 4
+---------
+
 .. include:: tutorial_example_04.php
    :literal:
 
@@ -209,13 +223,65 @@
 we can simply use foreach() to loop over all the contexts in the translation
 definition as you can see in lines 9 to 17.
 
+
 Caching
 =======
 
+As reading from an XML file for every translation context is not very fast -
+especially when the translation file has a lot of strings - the translation
+system benefits from a caching solution. Caching is implemented in the Cache_
+component and the links between this component and the caching component are
+implemented in the ezcTranslationCacheBackend_ which is located in the
+TranslationCacheTiein_ component.
 
+Using the cache backend is similar to using the Ts backend as you can see in
+the next example:
+
+Example 5
+---------
+
+.. include:: tutorial_example_05.php
+   :literal:
+
+Instead of setting up the Ts Backend we have to instantiate an
+ezcCacheStorageFileArray
+(line 4) which we then pass as sole parameter to the constructor of the
+ezcTranslationCacheBackend_ (line 5). The lines 7 to 13 are exactly the same as
+in `Example 1`_.
+
+When you try to run this script an ezcTranslationContextNotAvailableException
+is thrown because we did not put any contents in the cache yet. The
+ezcTranslationCacheBackend_ implements the ezcTranslationContextWrite interface
+and combined with a class that implements the ezcTranslationContextRead
+interface (such as ezcTranslationTsBackend) you can fill up the cache in a
+memory efficient way. The next example shows how to do this: 
+
+Example 6
+---------
+
+.. include:: tutorial_example_06.php
+   :literal:
+
+In the lines 4 to 6 we set up the reader interface, like we did in
+`Example 4`_. Then we continue in lines 8 to 10 to initialize the writer. You
+would want to keep the locale for both the reader and the writer the same of
+course. In line 12 we use foreach() to iterate over all the contexts through 
the
+reader interface and we use the ezcTranslationContextWrite::storeContext()
+method in line 14 to store the read context object to the cache. After we
+iterated over all the contexts and stored them we initialize the reader and
+writer in lines 17-18. After you ran this script, the script from `Example 5`_
+will work fine too (as the cache has now all the contexts).
+
+.. _ezcTranslationCacheBackend: 
TranslationCacheTiein/ezcTranslationCacheBackend.html
+.. _ezcCacheStorageFileArray: Cache/ezcCacheStorageFileArray.html
+.. _Cache: introduction_Cache.html
+.. _TranslationCacheTiein: introduction_TranslateCacheTiein.html
+
 More Information
 ================
 
+See the API docs for ezcTranslationManager (and of course the other classes in
+this component) for more information.
 
 
 ..

Added: packages/Translation/trunk/docs/tutorial_example_05.php
===================================================================
--- packages/Translation/trunk/docs/tutorial_example_05.php     2006-01-27 
11:47:18 UTC (rev 2049)
+++ packages/Translation/trunk/docs/tutorial_example_05.php     2006-01-27 
11:49:06 UTC (rev 2050)
@@ -0,0 +1,14 @@
+<?php
+require_once 'tutorial_autoload.php';
+
+$cacheObj = new ezcCacheStorageFileArray( dirname( __FILE__ ). 
'/translations-cache' );
+$backend = new ezcTranslationCacheBackend( $cacheObj );
+
+$manager = new ezcTranslationManager( $backend );
+$headersContext = $manager->getContext( 'nb_NO', 'tutorial/headers' );
+$descriptionContext = $manager->getContext( 'nb_NO', 'tutorial/descriptions' );
+
+echo $headersContext->getTranslation( 'header1' ), "\n";
+echo $descriptionContext->getTranslation( 'desc1' ), "\n";
+echo $descriptionContext->getTranslation( 'desc2' ), "\n";
+?>


Property changes on: packages/Translation/trunk/docs/tutorial_example_05.php
___________________________________________________________________
Name: svn:eol-style
   + native

Added: packages/Translation/trunk/docs/tutorial_example_06.php
===================================================================
--- packages/Translation/trunk/docs/tutorial_example_06.php     2006-01-27 
11:47:18 UTC (rev 2049)
+++ packages/Translation/trunk/docs/tutorial_example_06.php     2006-01-27 
11:49:06 UTC (rev 2050)
@@ -0,0 +1,19 @@
+<?php
+require_once 'tutorial_autoload.php';
+
+$reader = new ezcTranslationTsBackend( dirname( __FILE__ ). '/translations' );
+$reader->setOptions( array( 'format' => 'translation-[LOCALE].xml' ) );
+$reader->initReader( 'nb_NO' );
+
+$cacheObj = new ezcCacheStorageFileArray( dirname( __FILE__ ). 
'/translations-cache' );
+$writer = new ezcTranslationCacheBackend( $cacheObj );
+$writer->initWriter( 'nb_NO' );
+
+foreach ( $reader as $contextName => $contextData )
+{
+    $writer->storeContext( $contextName, $contextData );
+}
+
+$reader->deInitReader();
+$writer->deInitWriter();
+?>


Property changes on: packages/Translation/trunk/docs/tutorial_example_06.php
___________________________________________________________________
Name: svn:eol-style
   + native

Added: packages/TranslationCacheTiein/trunk/docs/tutorial.txt
===================================================================
--- packages/TranslationCacheTiein/trunk/docs/tutorial.txt      2006-01-27 
11:47:18 UTC (rev 2049)
+++ packages/TranslationCacheTiein/trunk/docs/tutorial.txt      2006-01-27 
11:49:06 UTC (rev 2050)
@@ -0,0 +1,30 @@
+eZ components - TranslationCacheTiein
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. contents:: Table of Contents
+
+Introduction
+============
+
+The TranslationCacheTiein ties together the Translation component with the
+Cache component.  This component only implements one class, the
+ezcTranslationCacheBackend which is a backend for the Translation component. 
+
+
+Installation
+============
+
+The installation and configuration of the eZ components environment is
+described in a separate article. Please refer to the `Components Introduction`_
+for instructions on installation and configuration of the eZ components library
+and the Base component.
+
+.. _Components Introduction: 
http://ez.no/community/articles/an_introduction_to_ez_components
+
+
+..
+   Local Variables:
+   mode: rst
+   fill-column: 79
+   End: 
+   vim: et syn=rst tw=79


Property changes on: packages/TranslationCacheTiein/trunk/docs/tutorial.txt
___________________________________________________________________
Name: svn:eol-style
   + native

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to