0
votes

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.)

2

2 Answers

1
votes

My backend classes usually output english strings with parameters left out. Example

["Good job %s you have %i points", "Paul", 10]

Then the key for the translation is the English string (since I don't really like message codes).

0
votes

Translation is for me totally a View issue except for clearly defined business reasons, like having to store displayed messages as shown. The latter could e.g. happen if you want to store a sent invoice as delivered to the client.