How to add a new string to a *.po file w/ a PO editor
Asked Answered
G

5

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.)

Gavriella answered 6/10, 2011 at 20:23 Comment(0)
P
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.

Peneus answered 6/10, 2011 at 22:48 Comment(4)
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?Cardon
@iamtheladylegend: Editing by hand is not automatable.Peneus
I have a case where I am adding words with %s for strings with link between ex. <a href="somelink">Link Name</a> 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 <a href="#">Link1</a>. You are <a href="#">Link2</a> welcome now. Now, above words like %1$s and %2$s are not included in PO files, any idea why?Cardon
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 makemessageWellmannered
S
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.

Sickert answered 9/6, 2015 at 9:39 Comment(2)
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.Hurt
Awesome, glad to hear @HurtSickert
L
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.

Linden answered 15/2, 2018 at 13:5 Comment(3)
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.Caisson
@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.Bedrabble
@Václav Slavík How do you do this in a Wordpress environment (with Polylang)?Caisson
M
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

Missioner answered 31/3, 2017 at 12:8 Comment(0)
B
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.

Boarfish answered 23/3, 2021 at 8:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.