Wednesday 18 April 2012 6:08:23 pm - 6 replies
Hi eZCommunity,
So, i'm on an eZ Community Project 2011.9
On a module and i've a GET variable to select the language.
I can fetch all the node and all the node's content in this language no problem
I've a select attribute and i need to i18n its value but it's translated in the siteaccess language and i want it to be in the language retrieved in the GET variable
I tried to change my site.ini > RegionalSettings > Locale in my module but no it doesn't work, i18n still in my default siteaccess language
So huge thanks if you have any idea...
Thursday 19 April 2012 10:00:37 am
Problem is.. how can i retrieve the translation from the correction translation.ts file...
As i see it right now, it's a huge process :
browse the translation folders
find the correct one
parse-it
create an associative array
and for each string :
check if translation exists
display it or the original one
It will be so great if i could just override the i18n loading file process!
Thank you, and if you see it differently i'm interested
Thursday 19 April 2012 2:28:07 pm
Quote from Côme EDELINE :Yeah! i'm on it, i will post the template operator i've created if it works
Thank you
Yes, that can be usefull for others ![]()
you can also imagine your language parameters optional (default Language should be use)
Thursday 19 April 2012 3:22:42 pm
As for every tricky things i do on eZ or i can't remember, i save it : http://nordmaor.com/articles/memo/i18n-custom/
Here is a resume of the code i've produced:
autoloads/eztemplateautoload.php
$eZTemplateOperatorArray = array();
$eZTemplateOperatorArray[] = array( 'script' => ''extension/extension_name/autoloads/myautoloads_operators.php',
'class' => 'myAutoloads',
'operator_names' => array( 'i18n_custom' ) );
autoloads/myautoloads_operator.php
class myAutoloads
{
public $Operators;
function operatorList()
{
return array( 'i18n_custom' );
}
function namedParameterPerOperator()
{
return true;
}
function namedParameterList()
{
return array( 'i18n_custom' => array( 'context' => array( 'type' => 'string',
'required' => true,
'default' => 'my_default_context' ),
'language' => array( 'type' => 'string',
'required' => false,
'default' => 'eng-GB' ) ) );
}
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters )
{
$ret = '';
switch ( $operatorName )
{
case 'i18n_custom':
$operatorValue = self::i18n_custom( $namedParameters['context'], $operatorValue, $namedParameters['language'] );
break;
}
}
/**
* Retrieve translation in specific language
* @params context STRING
* @params source STRING
* @params language STRING
*
* @return trans STRING
*/
function i18n_custom( $context, $source, $language)
{
$comment = null;
$localeCode = eZLocale::instance($language)->localeFullCode();
$ini = eZINI::instance();
eZTSTranslator::initialize( $context, $localeCode, 'translation.ts', false );
$man = eZTranslatorManager::instance();
$trans = $man->translate( $context, $source, $comment );
if ( $trans !== null ) {
return $trans;
}
eZDebug::writeDebug( "Missing translation for message in context: '$context'. The untranslated message is: '$source'", __METHOD__ );
return $source;
}
}
design/.../*.tpl
{'my string'|i18n_custom('my_context', 'jpn-JP')}
Modified on Thursday 19 April 2012 3:25:26 pm by Côme EDELINE
You must be logged in to post messages in this topic!