Translation
By using the Translation Manager it's possible to do translation of text into other languages or other forms.
At the moment it supports translation using Qt translation files
which are XML files and can be easily edited using Linguist,
it also supports 1337 ('Leet') and Bork dynamic translation, and random translation which is handled by
randomly picking one of it's sub translators to do the work.
Adding custom made translation handlers are easy, this way it's possible to get advanced dynamic
translations as well as supporting other file formats.
Key elements
The translation system is based around source, context and comment.
Source
The source is the original text which is used to create an MD5 to lookup translations.
Context
The context determines in which context the text belongs to meaning that it's possible to have the same text in two contexts
with different meaning.
Comment
The comment is used for finding a variant of a text, for instance in some languages the translation
must differ according to where it's used while in others the text should be the same. It is similar to
the context but will fallback to the default comment (the one with no comment name) if the specified
comment can't be found.
Example
The table below shows a test translation to Norwegian, notice that the Store Draft source is
translated to 1337 because there was no manual translation available.
TODO — Image not available in archive
Title: Translation Table Example (eZ i18n)
File: /doc/images/translation.jpg
What this image shows:
Screenshot of a test translation table to Norwegian. Shows source strings alongside their translated equivalents, with entries falling back to 1337 (leetspeak) translator output for strings without manual translations. Produced by the eZTranslator demo code using a sample .ts file.
Replacement instructions:
Reproduce by running the sample code from sdk/ezi18n/view/translate. Save as /doc/images/translation.jpg
See /sdk/missing.html for the full list of missing images.
The table was produced by the following .ts file:
<!DOCTYPE TS><TS>
<context>
<name>edit</name>
<message>
<source>Preview</source>
<translation>Forhaandsvisning</translation>
</message>
<message>
<source>Preview</source>
<comment>side-pane</comment>
<translation>Vis fram</translation>
</message>
<message>
<source>Versions</source>
<translation>Versjoner</translation>
</message>
<message>
<source>Versions</source>
<comment>side-pane</comment>
<translation>Tidligere verk</translation>
</message>
</context>
<context>
<name>default</name>
<message>
<source>Preview</source>
<translation>Vis</translation>
</message>
<message>
<source>Versions</source>
<translation>Versjon liste</translation>
</message>
<message>
<source>Translate</source>
<translation>Oversett</translation>
</message>
<message>
<source>Permission</source>
<translation>Rettigheter</translation>
</message>
<message>
<source>Some text</source>
<translation>Litt tekst</translation>
</message>
<message>
<source>Store Draft</source>
<translation type='unfinished'></translation>
</message>
<message>
<source>Send for publishing</source>
<translation>Send til publisering</translation>
</message>
<message>
<source>Discard</source>
<translation>Fjern</translation>
</message>
<message>
<source>Find object</source>
<translation>Finn objekt</translation>
</message>
</context>
</TS>
And the following code:
include_once( "lib/ezi18n/classes/eztranslatormanager.php" );
include_once( "lib/ezi18n/classes/eztstranslator.php" );
include_once( "lib/ezi18n/classes/ez1337translator.php" );
$trans =& eZTranslatorManager::instance();
eZTSTranslator::initialize( "edit.ts", "lib/ezi18n/sdk", false );
eZ1337Translator::initialize();
$texts = array(
"Preview",
array( "source" => "Preview",
"context" => "edit" ),
array( "source" => "Preview",
"context" => "edit",
"comment" => "side-pane" ),
array( "source" => "Preview",
"context" => "edit",
"comment" => "bottom-pane" ),
"Versions",
array( "source" => "Versions",
"context" => "edit" ),
array( "source" => "Versions",
"context" => "edit",
"comment" => "side-pane" ),
"Translate",
"Permission",
"Some text",
"Store Draft",
"Send for publishing",
"Discard",
"Find object"
);
print( '<table cellspacing="0">
<tr>
<th>Context</th><th>Source</th><th>Comment</th><th>Translation(nor-NO)</th>
</tr>
');
$seq = array( "bgdark", "bglight" );
foreach( $texts as $text )
{
$source = "";
$context = "";
$comment = null;
if ( is_array( $text ) )
{
if ( isset( $text["source"] ) )
$source = $text["source"];
if ( isset( $text["context"] ) )
$context = $text["context"];
if ( isset( $text["comment"] ) )
$comment = $text["comment"];
}
else
$source = $text;
$class = array_pop( $seq );
array_splice( $seq, 0, 0, array( $class ) );
$translation = $trans->translate( $context, $source, $comment );
if ( $context == "" )
$context = "default";
print( "<tr>
<td class=\"$class\">$context</td><td class=\"$class\">$source</td><td class=\"$class\">$comment</td><td class=\"$class\">$translation</td>
</tr>
" );
}
print( '</table>' );
|