2

I'm developing a multi-lingual site.

I've put a Zend_Translate object in the Zend_Registry and I use it to translate all static texts to the selected locale.

My question is how do I change the locale when the user chooses another language?

If I get the translate object from the registry, call setLocale , and put it again in the registry , will it hold only for that user or for the whole application?

Thanks.

Ran
  • 4,117
  • 4
  • 44
  • 70
  • I found out that using a controller plugin to set the locale of the zend translate in the registry works... is that the only way? – Ran Dec 05 '11 at 10:40
  • Probably not *the* only one, but if you would like to set it based on an URL parametre, then I would say it's at least the most convenient. – mingos Dec 05 '11 at 10:51

2 Answers2

2

You will need to use a plugin for that.

In short: create your plugin and add the routeStartup() and routeShutdown() methods to it. In the former one, set the locale string in a request param and, if needed, also set the requesr URI to contain the locale string. Correct locale string detection is up to you - you can either use a cookie, URL parametre, browser's accepted language header or any combination of the three. In the latter one, create your Zend_Translate object based on the locale you have set earlier.

Here is how it looks like in my CMS.

Here is a tutorial regarding the use of the language parametre in the URL. You may also check how I do it in my CMS (see the _initRouter method).

I hope this info is helpful.

mingos
  • 23,778
  • 12
  • 70
  • 107
0

Use Poedit for this purpose ..go thru this link for more

techie.ayyappadas.com/how-do-use-poeditor
coolguy
  • 7,866
  • 9
  • 45
  • 71
  • I have a translation file.. I need a php (zend) code to give the user an option to change the selected language. – Ran Dec 05 '11 at 10:40