I've created an application that should be partially translated into different languages. Currently I have a TMX file containing 2 languages (English and Dutch). It was set-up like this in the bootstrap file:
protected function _initTranslation(){
$translate=new Zend_Translate(
array(
'adapter' => 'tmx',
'content' => ROOT_DIR.'/translation/translation.tmx',
'locale' => 'nl'
)
);
$locale=null;
try{
$locale=new Zend_Locale(Zend_Locale::BROWSER);
}catch(Exception $e){
$locale=new Zend_Locale('en');
}
if(in_array($locale->getLanguage(), $translate->getAdapter()->getList())){
$translate->setLocale($locale);
}else{
$translate->setLocale(new Zend_Locale('en'));
}
Zend_Registry::set('trans', $translate);
}
Now there are additional languages like Danish, French, etc. that should be added but not all fields need to be translated. Is it possible to make Zend select one language as the default if it can not find a translation for a specific key.
eg.
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE tmx SYSTEM "tmx14.dtd">
<tmx version="1.4">
<header creationtoolversion="1.0.0" datatype="winres" segtype="sentence" adminlang="en-us" srclang="en-gb" o-tmf="abc" creationtool="XYZTool">
</header>
<body>
<!-- login screen -->
<tu tuid="login">
<tuv xml:lang="en"><seg>login</seg></tuv>
<tuv xml:lang="nl"><seg>inloggen</seg></tuv>
</tu>
<tu tuid="logout">
<tuv xml:lang="en"><seg>logout</seg></tuv>
<tuv xml:lang="nl"><seg>uitloggen</seg></tuv>
<tuv xml:lang="da"><seg>logge ud</seg></tuv>
</tu>
<!-- some additional languages keys come here -->
</body>
</tmx>
Since the srclang is en-gb. And a user from Denmark logs on the english version should be shown for the key login. Can this be done?
Yes, use the route option for Zend_Translate
(see http://framework.zend.com/manual/1.12/ru/zend.translate.additional.html#zend.translate.additional.rerouting):
$translate = new Zend_Translate(
array(
'adapter' => 'tmx',
'content' => ROOT_DIR.'/translation/translation.tmx',
'locale' => 'nl',
'route' => array('da' => 'en', 'fr' => 'en')
)
);