symfony: calling i18n functions from actions
Translation of the original in Catalan. Read it in: CatalàCastellano
A very powerful tool in symfony is internationalization (i18n), specifically the __() function becomes one of the most used and indispensable ones in the view layer of our applications. Since it then allows our application to be translated into whatever language in a very simple way. The problem is when, from the model part, we have to load information into objects that will then be shown directly by the view. If we want this information to be easily translatable even though it's in the model and not in the view layer, things get a little complicated. In fact, until today I didn't know how it was done and I've found out thanks to a snippet published on the symfony website.
Specifically symfony treats the __() function as what it calls a helper, which let us make our templates dynamic and give them a huge amount of power. If you don't know what helpers are I recommend you go over the symfony documentation, specifically the View chapter. In fact, symfony has many kinds of helpers: url, javascript, form, i18n, etc. we can even program our own helpers.
So what I'll comment on is how to use i18n type helpers from the model, but the rest of the helpers can also be invoked the same way.
First you have to think about including from the model the code where the helper functions are declared:
include_once('symfony/helper/I18NHelper.php');
To invoke the __() function, we have to do:
sfConfig::get('sf_i18n_instance')->__($text, $args, 'messages');
What I don't know is whether the translation tools that are dedicated to extracting the messages from the __() functions are capable of going through the action files defined in the model too or whether they only go through the templates. Although it can't be very difficult to tell them to also look at the model files.
Taking advantage of the fact that I'm talking about internationalization I recommend a tool for translating language files (XLIFF), it's a multiplatform tool programmed in java: open language tools XLIFF editor. As you can see the look and the simplicity are unbeatable. Ideal for non-technical people who can do the translations of the applications for us.

To generate the XLIFF files from symfony I recommend: HowToGenerateI18NFiles. It's a small manual that I've found on the symfony wiki.