2

I'm using gettext to write a multilingual php web app.

Whats the best way of actually using gettext, I can use it as a key phrase:

echo (_("main.welcomeText.1"));

Or

echo (_("Welcome to my site, we build great webapps."));

In both ways I use a .po file to translate the request ofcourse.

Whats the better way ?

Tzvi
  • 343
  • 1
  • 2
  • 15
  • 2
    possible duplicate of [Why do people use plain english as translation placeholders?](http://stackoverflow.com/questions/4232922/why-do-people-use-plain-english-as-translation-placeholders) – JJJ May 21 '12 at 12:28
  • Thanks for the comment but that thread isn't centered about what is better but more on the reasons people use the keyphrased way. – Tzvi May 21 '12 at 12:44

2 Answers2

2

It depends :):

  • you want better debugging
  • you want accurate translation
  • you want speed of programming
  • you want translator not to depends on developer to translate (impossible because developer do not write proper english... french,indian [include native and non native dev])
  • you want the best of 2 worlds

The best taught way is main.welcomText.1 because:

  • You will use it in lot of place (maybe) so copy past is easier and less error prone.
  • The key has a number witch is easier to search/sort when errors are throw ie: ...Bad key is error.errorCode.321 instead of "Bad things happened in class xy when using null"
  • The key cover the "meaning/semantics" so you have to push your mind a little bit more in order to structure/define your messages ie: main.hello or greeting.formal or greeting.friendly witch is different to translate (ie: "Hello", "Welcome","Hi")
  • Bonus: You can reduce the amount of translation by structuring keys using always the same key (in an easier way. think of refactoring

using "Welcome to my site, we build great webapps." make it easier to read and for translator to translate but is less easier to correct/debug especially if it's a lot of time in the code

So keys are used for debugging, so they should be easier to find where in your code they are.

EDIT: Provide the base English translation ie:

main.welcomeText.1:Welcome to my site, we build great webapps.

This is more work for the developer in short term. But few in large project :)

Krilivye
  • 547
  • 4
  • 8
  • 1
    Thanks, but my translator will see all the keys, who will he know how to translate to the source ? – Tzvi May 21 '12 at 12:47
0

I have never used gettext... and never really known anyone who has.

I would suggest a different approach, that is to use Smarty/Dwoo to separate presentation totally. Using this you can then have very simple config/language files to do internationalisation.

Brian
  • 8,418
  • 2
  • 25
  • 32
  • how does it manage to separate presentation totally? At one moment you have to tell in the code that you want to alert(msg1) isn't it? I'ld be glad to know more about it since I'm on it as well! – Sebas May 21 '12 at 13:11