Author: Derick Rethans
Date: 2006-01-26 17:07:25 +0100 (Thu, 26 Jan 2006)
New Revision: 2047

Log:
- Added Iteration example.

Added:
   packages/Translation/trunk/docs/tutorial_example_04.php
Modified:
   packages/Translation/trunk/docs/tutorial.txt

Modified: packages/Translation/trunk/docs/tutorial.txt
===================================================================
--- packages/Translation/trunk/docs/tutorial.txt        2006-01-26 15:57:43 UTC 
(rev 2046)
+++ packages/Translation/trunk/docs/tutorial.txt        2006-01-26 16:07:25 UTC 
(rev 2047)
@@ -96,8 +96,9 @@
 then construct a manager in line 7. In line 8 and 9 we ask the manager to
 return the contexts "tutorial/headers" and "tutorial/desciptions" for the
 "nb_NO" locale. When you ask the manager to retrieve the content it first
-checks its internal cache if the context is there already. If the context is
-available in the cache it will simply return it. If the context is not in the
+checks its internal cache if the ezcTranslation object for that context was
+already retrieved. If the object for the context is available in the cache it
+will simply return the ezcTranslation object. If the context is not in the
 cache, it will defer the retrieving to the backend, store the results in its
 cache and return the context.
 
@@ -118,11 +119,11 @@
    :literal:
 
 The first lines are the same as in the first example. But this time we retrieve
-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 (search_string and matches) for
-which the values are provided in array that is passed as second parameter to
-the getTranslation() method.
+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
+(search_string and matches) for which the values are provided in array that is
+passed as second parameter to the getTranslation() method.
 
 The translation for the English "The apple is round" is in Norwegian "Applet er
 rund". With the name of the fruit being the parameter you can see that in
@@ -191,10 +192,23 @@
 
 .. _Leetspeak: http://en.wikipedia.org/wiki/Leet
 
+
 Iteration
 =========
 
+In some situations it might be useful to iterate over all the contexts in a
+specific translation file. The backends which implement the
+ezcTranslationContextRead interface provide this functionality in the form of
+an Iterator. The ezcTranslationTsBackend is such a class. Using this interface
+is extremely easy, as you can see in the next example:
 
+.. include:: tutorial_example_04.php
+   :literal:
+
+In line 7 we initialize the reader with the locale 'nb_NO'. After this is done,
+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
 =======
 

Added: packages/Translation/trunk/docs/tutorial_example_04.php
===================================================================
--- packages/Translation/trunk/docs/tutorial_example_04.php     2006-01-26 
15:57:43 UTC (rev 2046)
+++ packages/Translation/trunk/docs/tutorial_example_04.php     2006-01-26 
16:07:25 UTC (rev 2047)
@@ -0,0 +1,18 @@
+<?php
+require_once 'tutorial_autoload.php';
+
+$backend = new ezcTranslationTsBackend( dirname( __FILE__ ). '/translations' );
+$backend->setOptions( array( 'format' => 'translation-[LOCALE].xml' ) );
+
+$backend->initReader( 'nb_NO' );
+
+foreach ( $backend as $contextName => $contextData )
+{
+    echo $contextName, "\n";
+    foreach ( $contextData as $context )
+    {
+        echo "\toriginal string:   {$context->original}\n";
+        echo "\ttranslated string: {$context->translation}\n\n";
+    }
+}
+?>


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

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

Reply via email to