1

From my previous questions about gettext, one of the biggest benefits of using PHP's gettext extension instead of other methods of language translation was that it is super easy to have other people make translation files with a program called Poedit.

Now I have gettext working in my app but I have not made any translation files yet, I found a demo file on the net and tested with it to conform my app works with gettext though.

Now I played around with poedit a little bit and I might be wrong, hopefully someone can clarify some issues.

  1. As far as I can tell poedit reads through your php code and finds all availabale spots to do a translation, is this correct?

  2. If the above is correct, then how do you have a human translator translate with poedit without having access to your app?

Or in simple terms is it possible to make a translation file with poedit without it having access to your php code?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
JasonDavis
  • 48,204
  • 100
  • 318
  • 537

3 Answers3

2

Note that I have never used poedit myself, so this might not be totally accurate...

An interesting article that you might first read, for some information : Localizing a WordPress Plugin Using poEdit. It's WordPress, which means PHP -- so the basic ideas should be OK for your application.

Basically:

  • you first extract all the strings from the PHP source code
    • by telling poedit how your translation function is called
    • this should answer your 1)
  • then, you do translation
    • working with/on the .po file
    • And I'm guessing you can distribute this .po file to your translators, who can then translate the strings it contains
  • and, finally, you use the .po file to generate the .mo file that will be used in your application.

This other article, about WordPress too, seems to indicate that I'm guessing right : User:Skippy/Creating POT Files -- especially, this sentence :

Make the .po file available for download (or optionally include it in the plugin archive). Translators will use this file to construct a .mo file, which will be used by the load_plugin_textdomain() function.

(Obviously, the function name you'll be using in your application will not be the same as the one in WordPress -- still, the idea is there).

halfer
  • 19,824
  • 17
  • 99
  • 186
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
  • 1
    thanks, you always put in so much effort into your answers +1 – JasonDavis Sep 13 '09 at 22:23
  • 1
    @jason : you're welcome :-) Here, I was curious about gettext : I suppose I'll be using it one day or another (especially as I'm currently working on a project that uses gettext -- even if I'm not the one responsible for the translation stuff) – Pascal MARTIN Sep 13 '09 at 22:24
  • I was hoping there was a way to create the original (first) fiel that gettext will use by hand in a text editor but it is looking like I will have to let poedit scan all my project files unless I find another method – JasonDavis Sep 13 '09 at 22:35
  • It would seem that .po files are just text files, with a special format (see http://en.wikipedia.org/wiki/GNU_gettext#Translating for a real basic example) ;; maybe you can find the definition of that format somewhere ? considering gettext is GNU, the format has to be open... – Pascal MARTIN Sep 13 '09 at 22:38
  • Here http://stackoverflow.com/questions/873017/poedit-workaround-for-dynamic-gettext is the main reason I would like to do it manually as I see a problem in the way it works, thanks for the link – JasonDavis Sep 13 '09 at 22:40
  • oh, I see -- but what about the solution proposed by raspi on that page ? http://stackoverflow.com/questions/873017/poedit-workaround-for-dynamic-gettext/874428#874428 – Pascal MARTIN Sep 13 '09 at 22:42
  • well my case is a little different, To use gettext you have to call the gettext or else _() as far as I know, well on my app I will be using a custom named function adn then that function will call the gettext function, so poedit will only see the actual gettext or _() called 1 time in the whole site inside of a function because poedit doesn't execute code, just reads files. I just successfuly was able to edit a .po file in a text editor and have gettext read it correctly though =) – JasonDavis Sep 13 '09 at 22:54
  • I should of read your wordpress link first, it appears poedit has a tab "keywords" when making a new project, you can enter in a custom function name there, this is great – JasonDavis Sep 13 '09 at 23:05
  • Reading your first comment, I was going to say "why don't you indicate that your translation function is called 'adn'", and then I saw you found out yourself -- nice :-) – Pascal MARTIN Sep 14 '09 at 04:05
  • @downvoter : I'm OK to be downvoted *(it's the way SO works ; even if being downvoted 4 months after my answer was accepted seems strange)*, but explaining what you find wrong in my answer might help *(both me, the OP, and the SO community as a whole)* : it would allow me to edit my answer, to enhance it :-) ;; Thanks in advance :-) – Pascal MARTIN Jan 26 '10 at 12:14
2

No, poEdit doesn't read all your sources. You use the gettext utility "xgettext" to do that.

Basically, xgettext will produce a .po file.

Your translators will use POEdit to work on that .po file.

When the translater is done, you'll compile the .po into an .mo, which you app will use to look up translations.

If you have gettext installed on some unixy system, try "info gettext" in bash.

timdev
  • 61,857
  • 6
  • 82
  • 92
  • @tim : the http://www.poedit.net/ page says : "You can use Poedit to scan source code for translatable strings." -- so it would seem you can use poEdit to read the source code ? – Pascal MARTIN Sep 13 '09 at 22:21
  • Oh, look at that! Haven't actually used gettext in a long time (it scarred me). Back then, i ended up scripting some stuff on the command-line to drive xgettext, and it worked well enough. I think the php-gettext extension had some decent-enough docs on the process.. – timdev Sep 13 '09 at 23:16
0

PoEdit actually uses xgettext, which you can set up on the Settings/Parsers tab correctly.

You should distribute a .pot file by the way, which is a .po template. So translators can translate it, set the language, the translator team, etc.

Unfortunately, I cannot see an option to create .pot file from source, but poedit can read then (of course, it's the same as .po).

After creating their own .po, you can have the .mo!

Peter O.
  • 32,158
  • 14
  • 82
  • 96
zimpee
  • 11
  • 3