[geeklog-devel] Question about internationalization and look-ups

Michael Jervis mjervis at gmail.com
Sun Feb 17 04:10:18 EST 2008


On Feb 9, 2008 2:46 PM, Tony Bibbs <tony at tonybibbs.com> wrote:
> I wouldn't suppose someone would have time to try and crack this one nut for me?

Ok the way I do it is to use the attached translate.class.php, it's
bootstrapped as follows:

/* Load core translation options: */
require_once 'Translate.class.php';
require_once SNMR_PATH_TO_LANG.'core.en.php';
$trans = new Translate($_LANGUAGE);

I construct my controllers passing in the global translate object
which becomes a member variable $i, this is done in the base class for
my controllers:

 /**
      * Constructor, does things like load the translator, template and
      * cache objects.
      *
      * @param $internationalise    object  Zend_Translate object.
      * @param $view                object  Zend_View object.
      * @param $db                  object  PHPBB3 DB layer.
      * @param $user                object  PHPBB3 User layer.
      * @param $user                object  PHPBB3 Auth layer.
      * @param $frontendDefaults    array   Default options for
Zend_Cache frontend.
      * @param $backendDefaults     array   Default options for
Zend_Cache backend.
      */
    public function __construct(&$internationalise, &$view, &$db,
&$user, &$auth,
                                $frontendDefaults, $backendDefaults) {
        $this->i    = $internationalise;
        $this->v    = $view;
        $this->d    = $db;
        $this->u    = $user;
        $this->auth = $auth;
        /* Cache defaults */
        $this->cacheOptions           = new StdClass();
        $this->cacheOptions->frontend = $frontendDefaults;
        $this->cacheOptions->backend  = $backendDefaults;
        /* View essentials */
        $this->v->baseUrl = SNMR_BASE_URL;
    }

Each controller then adds it's translations onto the code language set
in it's constructor:
$this->i->addTranslations('homePage', $this->u->data['user_lang']);

I then translate things and pass them into variables on the view
object for rendering:
$this->v->moreText = $this->i->_('More...');

My core language file (core.en.php) is actually dull:
<?php

$_LANGUAGE = array(
);
?>

Then each module has it's translation file (homePage.en.php for example):
<?php

$_LANGUAGE = array_merge($_LANGUAGE, array(
    'homepagewelcome' => 'Welcome to Snakenet',
    'TuneInBlock' => 'Tune In'
));
?>

So just wack a translation object into your view object, and in
buildDropDown throw everything through $this->i->_(); and translate
with files.

Alternatively, combine that with a lang column on each of your lookup
tables and frig your query to return where the language maps.

Either way, it's a pain in the arse to keep your translations in
synch, but, at least with My Way you always get a default string
(typically in English).

Cheers,

Mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Translate.class.php
Type: application/octet-stream
Size: 1096 bytes
Desc: not available
URL: <https://pairlist8.pair.net/pipermail/geeklog-devel/attachments/20080217/8407a6ce/attachment.obj>


More information about the geeklog-devel mailing list