22

I MANUALLY created a file: test.po with the contents:

msgid "greeting"
msgstr "Hello World"

Now I can edit the translation (hello world) in editors like "poedit" and "GTranslated" (I'm using Ubuntu). I can even add comments to that translation. However neither "poedit" and "GTranslated" will let me ADD a new translation string - I've looked online to no avail and looked at screenshots of other editors and none seem to have a "new" button.

What am I missing??? It seems stupid to have to edit new keys w/ a "plain" text editor and then edit them in these PO editors (whichever they may be). (If you can't tell I'm new to this 'gettext' world - I'm building a website in Zend/PHP.)

pirhac
  • 887
  • 2
  • 8
  • 16

5 Answers5

20

You should never be adding strings directly to a .po file; they will be added by msgmerge from the .pot file generated by xgettext.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • I have a scenario, where I needs to add two words only into PO file, for that opening and re-generating PO files seems a little long way, don't you think? – Aditya P Bhatt Feb 08 '13 at 06:05
  • 2
    @iamtheladylegend: Editing by hand is not automatable. – Ignacio Vazquez-Abrams Feb 08 '13 at 06:07
  • I have a case where I am adding words with %s for strings with link between ex. Link Name and currency data with %d ex. $123.00 while a string which have multiple links in single word, are entered like, %1$s and %2$s for ex. Hello Link1. You are Link2 welcome now. Now, above words like %1$s and %2$s are not included in PO files, any idea why? – Aditya P Bhatt Feb 08 '13 at 06:09
  • 1
    What if the source of my strings is in a database for example. How do I get the messages to be made then in the po file? Compilemssage seems to ignore everything not previously grabbed by makemessage – EvilSmurf Aug 14 '18 at 14:59
13

Here's what I did:

Edit the .po file and add your new string, for example:

msgid "All Catalogues"
msgstr "Todos los catalogos"

Save the .po file.

Now open it in poedit and in the menu select: Catalog > Update from POT file

Once you've updated you should see the new string and will be able to change it.

Save changes and you're good to go.

Edu Wass
  • 1,969
  • 1
  • 21
  • 22
  • 1
    My use case might be slightly different since I *am* using a POT file. Regardless, your answer still helped me. To add a new translation manually, I added the code you specified to the **POT file**, and then opened my .po translation in poedit and selected Catalog > Update from POT as you suggested. Worked perfectly. – rinogo Mar 17 '17 at 00:12
  • Awesome, glad to hear @rinogo – Edu Wass Mar 17 '17 at 14:39
5

MacOS:

  1. Edit the .po file in any text editor.
  2. Open the .po file in Poedit (free)
  3. In Poedit, select file -> Compile to .MO

This is what worked for me in a Wordpress Genesis .po file.

Khawaja Asim
  • 1,327
  • 18
  • 38
Pasqualito
  • 51
  • 1
  • 2
  • So all poedit is doing is compiling the .mo file? It seems a bit odd you can't add entries in poedit. I think this is at the root of the OP's puzzlement - it's why I came here. – Chris Pink Mar 22 '22 at 13:52
  • @ChrisPink That's how the gettext translation system works. You don't add strings manually, because they come from source code - if something isn't in the code, it makes no sense to translate it, the translation would never be *used*. So instead of doing all that manually, you automatically extract all texts to translate from the code. – Václav Slavík Mar 23 '22 at 11:49
  • @Václav Slavík How do you do this in a Wordpress environment (with Polylang)? – Chris Pink Mar 24 '22 at 12:28
1

open the .po file with any text editor, add these line or what ever the text need to added.

msgid "All Catalogues"
msgstr "Todos los catalogos"

save and launch :-D

Alaa M. Jaddou
  • 1,180
  • 1
  • 11
  • 30
1

Old thread but I found myself wanting to translate strings that are stored in the WordPress database and not translatable with Polylang.

What I did was creating a PHP file in the theme and I added strings with __("A string to translate"); The PoEdit automatically added it to the .po file.

Pierre
  • 4,976
  • 12
  • 54
  • 76