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

Tony Bibbs tony at tonybibbs.com
Tue Feb 19 13:52:18 EST 2008


I was thinking more along the lines of having you check out the GL2 codebase and whip up a working sample ;-)

Seriously if you don't have the time I'd understand but if you do that'd fix a big problem for me.  I can probably have something in SVN in alpha quality by the end of the week or early next week at the latest.

--Tony

----- Original Message ----
From: Michael Jervis <mjervis at gmail.com>
To: Geeklog Development <geeklog-devel at lists.geeklog.net>
Sent: Sunday, February 17, 2008 3:10:18 AM
Subject: Re: [geeklog-devel] Question about internationalization and look-ups


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


-----Inline Attachment Follows-----

_______________________________________________
geeklog-devel 
mailing 
list
geeklog-devel at lists.geeklog.net
http://eight.pairlist.net/mailman/listinfo/geeklog-devel







More information about the geeklog-devel mailing list