ÉricP
ÉricP

Reputation: 853

What are the step you have to go through when updating an application to be multilingual?

I need to update an application which is built on Zend Framework.

Most of the text is hard-coded in views scripts, forms, etc.

The application will be available in say, 3 languages AND is language specific (the content is not the same for all) and will have one domain per language (ie: mygreatsite.com, monsupersite.com, ilmiosupersite.com, etc.)

First question:

What is the best way to "handle" this kind of application?

I can imagine several solution like:

Second question:

What should I need to know about the existing code to start the "migration"?
What about any best practice when building a i18n website?
What are the best adapter? (I already used gettext() and I think it's the best)

Upvotes: 1

Views: 119

Answers (1)

Lee
Lee

Reputation: 1106

I am by no means an expert but this is what I do.

I use array as my translation adapter because it’s easier for my clients to update as they are just regular Joes. And I use translation keys instead of sentences. For example Some people would use

$this->translate(‘Some sentence to translate’); 

I use

$this->translate(‘default-index-dashboard-title’);

This makes it far easier for me to know where the text I’m looking for is to change. I don’t know if there are any advantages other than that though.

You will need to setup your translation adapter and translation cache (if you want) in your bootstrap. I do mine like this:

protected function _initLocale()
{
    $locale = new Zend_Locale(Zend_Locale::BROWSER);
    $config = Zend_Registry::get('config');
    Zend_Registry::set('Zend_Locale', $locale->toString());
    return $locale;
}

protected function _initTranslation()
{
    try{
        $translate = new Zend_Translate(array('adapter' => 'array', 'content' => ROOT . '/callmanagement/languages/' . strtolower(Zend_Registry::get('Zend_Locale')) . '.php'));
    }catch(Exception $e){
        $translate = new Zend_Translate(array('adapter' => 'array', 'content' => ROOT . '/callmanagement/languages/en_gb.php'));
    }

    Zend_Registry::set('Zend_Translate', $translate);
    return $translate;
}

I would use a single code base unless the sites are completely different and store the shared data in one database and have other databases for the site specific stuff.

You can setup multiple db adapters either in the bootstrap or in the congfig.

$dbLocal = new Zend_Db_Adapter_Pdo_Mysql(array(
        'host'     => 'localhost',
        'username' => $result['user'],
        'password' => $result['password'],
        'dbname'   => $result['database']
    ));
    Zend_Db_Table_Abstract::setDefaultAdapter($dbLocal);

    $dbShared = new Zend_Db_Adapter_Pdo_Mysql(array(
        'host'     => 'localhost',
        'username' => ‘root’,
        'password' => 'pass',
        'dbname'   => 'dbname'
    ));

    Zend_Registry::set('db_local', $dbLocal);
    Zend_Registry::set('db_shared', $dbShared);
    return $dbLocal;

You can get Zend Form to translate for you just put your translation key into the label field.

$this->addElement(‘text’, ‘test’, array(‘label’ => ‘translation-key’, ‘required’ => true)); etc.

Then if you are using Zend_Db_Table_Abstract classes you can change the default schema and database connection like this:

class Default_Model_Table_Topics extends Zend_Db_Table_Abstract 
{
protected $_name = 'topics';
protected $_id = 'topic_id';
protected $_rowClass = 'Default_Model_Topic';

protected $_schema = 'dbname';
protected $_adapter = 'db_shared';

}

If you need any more examples I’ll try and help.

Upvotes: 1

Related Questions