2

The Symfony documentation says:

Using Real or Keyword Messages This example illustrates the two different philosophies when creating messages to be translated:

$translated = $translator->trans('Symfony2 is great');

$translated = $translator->trans('symfony2.great');

< snip >

The choice of which method to use is entirely up to you, but the "keyword" format is often recommended.

So when would you use 'Real' messages?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Boy Baukema
  • 2,908
  • 1
  • 27
  • 38

4 Answers4

3

You really have to decide for yourself. It's a bit a matter of taste and a bit a matter of your translation workflow.

Real messages are good when you don't want the overhead of maintaining an additional translation file (for the origin language). Furthermore, if you forget to translate some of the messages, you'd still see a valid message in the origin language. It's also somewhat easier to translate from an original message rather than a keyword.

Keywords are better when messages are changing often, especially with long texts. You abstract away the purpose of a message from the actual text.

EDIT: there's one more scenario when you could argue that real messages are better than keys - when your website only supports one language but with multiple variations - like en_GB, en_US. Most of the messages will be the same, only few will vary. So most of the messages could be left as they are, and only the ones which are actually different between GB and US put into a translation files. It would require much less work compared to an approach with using keys (of course, assuming your messages don't change very often).

Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125
1

One usecase for the real format I could come up with is when messages are created by users via the UI — it would be silly to force them to come up with keywords for each phrase they want to translate.

I haven't had such a need yet, so I always use the keyword format.

Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
0

Real messages has no big interest. IMO you can use them if you are sure your application will always be mono-language and you want to gain a few minutes in development.

Keyword trans has the interest that if you have to translate your website, you'll see immediately if a translation is missing. To facilitate translations, I personnaly use JMSTranslationBundle

Paul Andrieux
  • 1,836
  • 11
  • 24
  • Opinions as >They are used when you are too lazy to create a translation config file for an application in one unique language can hardly be considered an answer, it has nothing factual in it. – DRvanR Sep 02 '13 at 18:49
0

For the most part I agree with @Jakub Zalas' answer, however, the last line is a bit off.

Keywords are better when messages may ever change - not just when changing often. This is outlined as well in the docs themselves:

The second method is handy because the message key won't need to be changed in every translation file if you decide that the message should actually read "Symfony2 is really great" in the default locale.

If the message changes and you haven't used a key but the message as key you have to change any code using this message to reflect that change. More places to change are more potential bugs. We have the ability to build in leverage by using message keys.

Community
  • 1
  • 1
DRvanR
  • 399
  • 3
  • 11
  • Symfony provides automated tasks which update the translation files. Incorporating them in your workflow would make that you don't miss anything. – Jakub Zalas Sep 03 '13 at 12:58
  • @JakubZalas , I agree that that would be the case if someone *would* incorporate that in the workflow, however since that is opinionated behavior (one should do X) rather then dictated behavior (one must always do X) it is not something that can be assumed. I just expanded on what is in the manual. The whole command is not even mentioned in the book. Furthermore, there are bundles as the by @ PaulAndrieux mentioned JMSTranslationbundle that provide more/different functionality. – DRvanR Sep 03 '13 at 13:39