Where to translate message strings - in the view or in the model?

Posted by GrGr on Stack Overflow See other posts from Stack Overflow or by GrGr
Published on 2009-06-05T09:37:38Z Indexed on 2010/03/14 17:05 UTC
Read the original article Hit count: 213

We have a multilingual (PHP) application and use gettext for i18n. There are a few classes in the backend/model that return messages or message formats for printf().

We use xgettext to extract the strings that we want to translate.

We apply the gettext function T_() in the frontend/view - this seems to be where it belongs. So far we kept the backend clean from T_() calls, this way we can also unit-test messages.

So in the frontend we have something like

echo T_($mymodel->getMessage());

or

printf(T_($mymodel->getMessageFormat()), $mymodel->getValue());

This makes it impossible to apply xgettext to extract the strings, unless we put some dummy T_("my message %s to translate") call in the MyModel class.

So this leads to the more general question:

Do you apply translation in the backend classes, resp. where do you apply translation and how do you keep track of the strings which you have to translate?

(I am aware of Question: poedit workaround for dynamic gettext.)

© Stack Overflow or respective owner

Related posts about internationalization

Related posts about xgettext