Is there a good i18n extension?

Hi,

I’m new to Yii and I think it’s an amazing, really great framework.

Unfortunately it seems it does have a weakness: internationalization (i18N).

Yii’s built-in i18n mechanism has a very obvious design fault, in that the whole text of a message in the “source application language” has to be used to reference messages. The main (but not only) problem of this approach is that if you want to change a message in the language that happens to be the “source application language”, you have to do a search and replace throughout your whole code - that alone is enough for making it completely unviable. A partial workaround is to use a fictitious source application language, but even that way it is cumbersome because stuff like plural form syntax has to be included into the source messages.

This has been discussed here: http://www.yiiframework.com/forum/index.php/topic/15363-changes-in-translations/page__p__76314__hl__tran+lation+find+replace#entry76314

So my question is, is there, or does anybody know, some extension that handles i18n in a better way? Similar to that used in most multilanguage frameworks, such as for example in Android applications? where there is no "source application language" at all, and a string ID is used to refer to messages?

(and hopefully one that still has some sort of plural form management)?

thanks in advance

m.

I believe that you are wrong. You can ‘force’ translation even when the source and target languages are the same, and thus solve this problem by setting… yep - “forceTranslation” to true in main.php config file:


'messages' => array(

    'forceTranslation' => true,

),



This way, messages sources in your code, assuming that are written in English, will still be translation into English when Yii::t() is called. See more in the API documentation.

I don’t think that solves the issues I mentioned. Or am I missing something?

Unless I missed something then “forceTranslation” will solve exactly what you’re looking for. Example:

Say your application source language is en_us (actually, source locale I think is more accurate to say), and the target language that the current surfer is using is no other than our favorite "en_us" as well.

  • If you don’t have forceTranslation turned on you get the problem you referred to.
  • If you have forceTranslation turned on and assuming the translation API call is something like [font="'Courier New"]Yii::t(“word_of_advise”, ‘That has been a useful forum thread! (hopefully :-)’)[/font], then you simply have to make sure to have the translation file (if you use the default CPhpMessageSource component) named [font="'Courier New"]…/en_us/word_of_advise.php[/font] in the appropriate directory - depending on where that API is made from - module, other, etc. - has that message in it as ‘key’ in the array returned from this file. In this case, you’ll get translation occurring even though the source and target languages are the same.

This is a basic design issue in translations that I’m pretty sure Yii’s dev team has been familiar with from past experience. I’m familiar with it from my work on Drupal. It suffers from that design flaw and the solution on Drupal was to define the application source language as a language that the application will never run in - either an invented language (you can do that in Drupal) or some really remote language (let your imagination run wild here).

That seems to solve the biggest issue then (changing an english message without having to replace thousands of occurrences of the same text in code).

However, plural form expressions still need to be in the key, right? There’s no solution to that, or is there?

ehh… didn’t deal with plural forms et al. You’re invited to share your findings when you reach 'em.