You're in the army now
Posts tagged translate
translate($this)
Nov 26th
So I needed to set up a translatable website and thought I would re-visit the way I use the translate component from the Zend framework. Previously I set up the translate component and would then create a plugin to handle the language change which I would trigger by changing a session variable.
Although this works I tended to feel it was a bit slap dash and that there must be a more efficient and useful way of utilising the component without the need to utilise a plugin.
So having had a nose around the net I decided that I wanted to make the language URL driven. I also wanted to steer away from using a subdomain to drive the language selection (i.e. en.website.com/pagename) and wanted it to be a part of the url (i.e. website.com/en/pagename) as this was more in keeping of the style of site I like to use.
So with a little tweaking code and utilising both the Locale, Translate and Router Resources here is how I did it.
More >
Zend Lego – Initialise, Part 2
Mar 6th
In this part I am going to go through setting up some translation methods and setting up your database connection.
initTranslate()
Zend_translate provides us with a very powerful way of translating text in a website, I would strongly recommend reading the manual for more info on the full extensibility of the component.
I tend to use the GetText method of translation. Mainly due to its increased speed over other methods as it is a compiled source rather than plain text. If this sounds daunting then dont worry as there are a number of free applications that will help you to build the files you need… I use a combination of POEdit and the GTEditor Plugin for Eclipse. POEdit is by far the more powerful of the two as it will compile the relevant files for you as well as attempt auto translation. Gted only allws for the editing of the human readable source but I find it is a nice clean and intuitive interface.
So here is the code to throw into your Initialise class.
public function initTranslate()
{
$settings = Zend_Registry::get('settings');
if (Zend_Registry::isRegistered('Zend_Cache')) {
Zend_Translate::setCache(Zend_Registry::get('Zend_Cache'));
}
$options = $settings->translate->options->toArray();
$locale = Zend_Registry::get('Zend_Locale');
Zend_Registry::set('Zend_Translate',
new Zend_Translate('gettext',
$settings->translate->path ,
$locale->toString() ,
$options));
}

