I have a web that is translated into 3 languages. But as I am affaid of heavy DB trafic, I do not use DB to store translations, but a simple associative array with cca 300 rows, each row contains 3 strings (for each language one string).
Now question. If I use DB, will it slow down my application? … Because if I make one SQL query per translated item, I will make many queries per page just to translate a few words plus queries to save and read data.
I can’t answer your for optimization, or access times for db translation at all, because I began using Yii::t() at first. But outside main menu, I ended up dropping that approach and creating duplicate views : if Yii webapp finds the view in a ‘en’ subfolder, it’ll display it instead of the master view in the parent folder.
I think it can even be mixed with partial renders in order not to repeat irrelevant parts of code (ie not needing translation).
Well I don’t know if I was clear enough or if it helps, but it’s really hot here these days
There’s surely a possibility to get the translations with one query, but as you don’t know which translations you need before, you must get all of them at the beginning and save them in an array. Your getMytranslation function returns then the value of that translation array.
In fact i18n in yii is not that difficult. You should read this section in the yii guide once more because in my opinion it is simplier to store your translations in a text file.
However if you want to try the database approach you should think of caching techniques.