Bug 990 - [Chameleon - Core] add capbaility to load language resource files
: [Chameleon - Core] add capbaility to load language resource files
Status: RESOLVED FIXED
: Chameleon
Core
: 2.2
: PC Linux
: P2 enhancement
: ---
Assigned To:
:
:
:
:
:
  Show dependency treegraph
 
Reported: 2005-03-18 09:20 by
Modified: 2005-03-18 09:21 (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2005-03-18 09:20:45
this is a small enhancement to provide a hook in the chameleon core to load
language-specific resource files.  Resource files are php scripts that provide a
loadResources($oApp) function that does the actual loading.

Modifications are:
* add a new array maszResourceFiles to Chameleon to keep a single resource file
per language
* modify CWCAddRegionalTemplate to accept optional third parameter that
specifies the resource file
* modify CWCSetTemplate to include resource file and invoke loadResource
function if a resource file is set for the current template

Modifications will be done so that it everything will work exactly the same if
no resource file is provided.  This provides the flexibility to use a single
template or multiple templates and manage translations either in the template or
in a separate file.

The initial intent is to have the loadResources() function insert
language-specific values using setVar so that template translation can be done
using [$str1|English$] type of syntax, removing the need for duplicated templates

In this model, the index.phtml file will contain:

$oApp->CWCAddRegionalTemplate( 'en-CA', 'sample_bilingual.html',
'resource_en.php' );
$oApp->CWCAddRegionalTemplate( 'en-CA', 'sample_bilingual.html',
'resource_fr.php' );

resource_en.php contains:

<?php

function loadResources( $oApp )
{
    $aRes['str1'] = 'English';
    $aRes['str2'] = 'fr-CA';
    $aRes['str3'] = 'French';
    
    foreach($aRes as $key=>$val)
    {
        $oApp->setVar($key, $val);
    }
}
?>

resource_fr.php contains:

<?php

function loadResources($oApp)
{
    $aRes['str1'] = 'French';
    $aRes['str2'] = 'en-CA';
    $aRes['str3'] = 'English';

    
    foreach($aRes as $key=>$val)
    {
        $oApp->setVar($key, $val);
    }
}
?>

and the template contains

current: [$str1|English$]
switch to: <a href="javascript:setLanguage('[$str2|fr-CA$]')">[$str3|French$]</a>
------- Comment #1 From 2005-03-18 09:21:13 -------
added in chameleon cvs (head branch - 2.1 - only)