Translations

I have begun work on a multi lingual website and so am curious to know what is the advantage of the very verbose Yii messages? For example, I see things like this, all thrown into an array:




'Active record class "{class}" does not have a scope named "{scope}".' => 'La clase de registro activo "{class}" no tiene un ámbito llamado "{scope}".',



I suspect that this array is in memory all the time.

I am accustomed to doing this by including a relevant language file which only contains translations for the particular view and is only kept in memory for the view render, eg.





  include('languages/' . Yii::app()->getLanguage() . '/my_file.php');


// and within that file:


  define('TEXT_NO_SCOPE', 'La clase de registro activo %s no tiene un ámbito llamado %s.');




So, in what way is the Yii method better?

Yii’s translation system has many nice features. Some of them:

  • You can auto-extract all your messages and update your translation catalogues automatically

  • Yii::t() supports placeholders and plural forms

  • You can switch to another translation source, for example from file based to DB based (e.g. to build a backend tool for translation)

  • You can define categories for your translations

  • Tranlsations can be cached

I’m sure, i’ve missed some other features. All this comes built in and ready to use. But if you don’t need any of the above it’s also fine to stick with your custom solution.

Hello Mike,

Thanks for your reply.

I will actually be using both file and database translations. The file based translations are for anything that doesn’t normally change - the template mainly. I think I will stick with the KISS principle :)

I have a database that I have reworked to be better suited to requirements (it was a dog!) and that includes language based tables, eg. cms_lang. These use a language_id column which I will need to set in Yii::app()->params according to selected language, which is simple enough.

I have to say that Yii is an amazing framework to work with and very easy to adapt. Here is another site I have in development, after only one week of development: http://www.suomedia.com/books It amazes me that something can be devloped from scratch so FAST!!