Use i18n in php

Author Message

Paul Etienney

Sunday 05 December 2010 10:04:05 pm

Hello eZ riders,

My question is very simple yet i did not find the right resource.

I need to translate text in a php module using the same mechanism as the i18n operator but i can't find the way to make this code work properly :

$language = ezcurrentLanguage();            
if ( $language != "eng-GB" )
{
$file = 'translation.ts';
$ini = eZINI::instance();
$useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
eZTSTranslator::initialize( $context, $language, $file, $useCache );
$man = eZTranslatorManager::instance();
$newValue = $man->translate( $context, $value, $comment );
if ( $newValue )
{
$value = $newValue;
}

Thanks

-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney

Daisy Radix

Sunday 05 December 2010 11:29:22 pm

Hello,

Check the file kernel/common/ezpi18n.php ( tr function) :)

eZ Publish certified developper :http://auth.ez.no/certification/verify/378142

Paul Etienney

Friday 24 December 2010 8:58:02 am

Shame on me ! It was soooooooo easy !

If you want to user the i18n operator in php module just do this :

eZTranslateText( 'contextName', 'text to translate');

And that's it !

Merry Christmas.

-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney

Nicolas Pastorino

Friday 24 December 2010 11:16:26 am

"

Shame on me ! It was soooooooo easy !

If you want to user the i18n operator in php module just do this :

eZTranslateText( 'contextName', 'text to translate');

And that's it !

Merry Christmas.

"

Merry Christmas to you too !

But...i could not get a hold on this eZTranslateText function (4.4) :)

I usually use the following :

ezpI18n::tr( $context, $source, $comment = null, $arguments = null )

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

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 18 2025 02:19:23
Script start
Timing: Jan 18 2025 02:19:23
Module start 'layout'
Timing: Jan 18 2025 02:19:23
Module start 'content'
Timing: Jan 18 2025 02:19:24
Module end 'content'
Timing: Jan 18 2025 02:19:24
Script end

Main resources:

Total runtime0.7606 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 588.9063152.6094
Module start 'layout' 0.00610.0030 741.515639.4219
Module start 'content' 0.00910.7500 780.9375600.4453
Module end 'content' 0.75900.0016 1,381.382812.1953
Script end 0.7606  1,393.5781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4280160.0002
Check MTime0.00140.1799160.0001
Mysql Total
Database connection0.00060.079010.0006
Mysqli_queries0.701492.2101620.0113
Looping result0.00070.0955600.0000
Template Total0.720894.820.3604
Template load0.00200.257020.0010
Template processing0.718894.503520.3594
Template load and register function0.00010.013510.0001
states
state_id_array0.00200.260710.0020
state_identifier_array0.00260.338620.0013
Override
Cache load0.00170.2180330.0001
Sytem overhead
Fetch class attribute can translate value0.00080.102330.0003
Fetch class attribute name0.00140.184970.0002
XML
Image XML parsing0.00180.230330.0006
class_abstraction
Instantiating content class attribute0.00000.001880.0000
General
dbfile0.00140.1783280.0000
String conversion0.00000.001040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs