Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gettext: Is it a good idea for the message ID to be the english text?

We're getting ready to translate our PHP website into various languages, and the gettext support in PHP looks like the way to go.

All the tutorials I see recommend using the english text as the message ID, i.e.

gettext("Hi there!")

But is that really a good idea? Let's say someone in marketing wants to change the text to "Hi there, y'all!". Then don't you have to update all the language files because that string -- which is actually the message ID -- has changed?

Is it better to have some kind of generic ID, like "hello.message", and an english translations file?

like image 885
Sean Avatar asked Oct 19 '08 14:10

Sean


2 Answers

Wow, I'm surprised that no one is advocating using the English as a key. I used this style in a couple of software projects, and IMHO it worked out pretty well. The code readability is great, and if you change an English string it becomes obvious that the message needs to be considered for re-translation (which is a good thing).

In the case that you're only correcting spelling or making some other change that definitely doesn't require translation, it's a simple matter to update the IDs for that string in the resource files.

That said, I'm currently evaluating whether or not to carry this way of doing I18N forward to a new project, so it's good to hear some thoughts on why it might not be a good idea.

like image 68
dcstraw Avatar answered Sep 19 '22 06:09

dcstraw


I strongly disagree with Richard Harrisons answer about which he states it is "the only way". Dear asker, do not trust an answer that states it is the only way, because the "only way" doesn't exist.

Here is another way which IMHO has a few advantages over Richards approach:

  • Start with using the proto-version of the English string as Original.
  • Don't display these proto-strings but create a translation file for English nontheless
  • Copy the proto-strings to the translation for the beginning

Advantages:

  • readable code
  • text in your code is very close if not identical to what your view displays
  • if you want to change the English text, you don't change the proto-string but the translation
  • if you want to translate the same thing twice, just write a slightly different proto-string or just add 'version for this and that' and you still have a perfectly readable code
like image 43
markus Avatar answered Sep 22 '22 06:09

markus