PHP: how to tell ezi18n which language to use?

Author Message

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;
}

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 04:23:19
Script start
Timing: Jan 31 2025 04:23:19
Module start 'layout'
Timing: Jan 31 2025 04:23:19
Module start 'content'
Timing: Jan 31 2025 04:23:19
Module end 'content'
Timing: Jan 31 2025 04:23:19
Script end

Main resources:

Total runtime0.0139 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 588.2656151.2266
Module start 'layout' 0.00470.0024 739.492236.6797
Module start 'content' 0.00710.0053 776.171990.3125
Module end 'content' 0.01250.0014 866.484429.9922
Script end 0.0138  896.4766 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002518.0906140.0002
Check MTime0.00128.6797140.0001
Mysql Total
Database connection0.00085.593210.0008
Mysqli_queries0.001913.961530.0006
Looping result0.00000.115310.0000
Template Total0.00107.610.0010
Template load0.00085.780710.0008
Template processing0.00021.746310.0002
Override
Cache load0.00064.048210.0006
General
dbfile0.00139.658780.0002
String conversion0.00000.051640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs