Pascal Specht
|
Thursday 23 October 2008 11:57:17 am
Hello there! I'm looking for a PHP function that could explicitely translate a given text into a language context, something like:
$lang 'fre-FR';
// does not exist!
$french = ezi18n( 'context' , 'english text' , $lang ) ;
but unfortunately, there's no such a language parameter in this function. Does somebody have an idea how to force a translation to a language?
Thanks in advance, </Pascal>
|
Pascal Specht
|
Friday 24 October 2008 12:09:33 am
If someone faces the same challenge some day, here's how I solved it:
function &translate_to_lang( $context, $source ,$language ) {
$ini =& eZINI::instance();
$file = 'translation.ts';
$comment = null;
// translation.ts translation
$useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
eZTSTranslator::initialize( $context, $language, $file, $useCache );
$man =& eZTranslatorManager::instance();
$trans = $man->translate( $context, $source, $comment );
if ( $trans !== null ) {
$text = ezinsertarguments( $trans, $arguments );
return $text;
}
eZDebug::writeWarning( "No translation for file(translation.ts) in context($context): '$source' with comment($comment)", "ezi18n" );
$text = ezinsertarguments( $source, $arguments );
return $text;
}
|