Preparation of the text strings to be translated with PoEdit and creation of Catalogs

As an annex to tutorial of PoEdit published previously, today we are going to try to know and learn how to prepare literal strings so that PoEdit the recognize as elements a translate.

If you are one of those who like to "gut" files (and if you like GNU / Linux, it is more than likely that it is), I am sure you will be interested in this process, which, on the other hand, is quite simple.

This is a contribution from Daniel Durante, thus becoming one of the winners of our weekly competition: «Share what you know about Linux«. Congratulations Daniel!

Translating a simple C program

We already mentioned in a previous PoEdit tutorial an example in which from an .html file from any website, we obtained a .pot file, and from this one .po which was the one that was ultimately going to be about the one who carried out the work of translator. The same goes for a C ++ program, a snippet of PHP or Javascript included in an .html file, a Java applet, or anything else you can imagine.

Let's see an example in a simple C language program:

#include 
int main () {

printf ("Hello World");

0 return;
}

In it we see strings in the English language and characters of the C language. The latter, as they are specific to the language, do not need to be translated, so we must differentiate in this paragraph what should be translated and what should not, because it is merely « computer code '. This is where the gettext function comes in, in the format gettext ($ string) or its alias _ ($ string)

Applying it to the previous example,

#include 
int main () {

printf (.gettext ("Hello World"));

0 return;
}

You need to put a period before the gettext function for PoEdit to work smoothly. The line where the literal 'Hello World' appears could also have been prepared as follows,

printf (._ ("Hello World"));

How does PoEdit know that the rest of the program is C code?

Open the PoEdit preferences and look at the following window,

and, if you are more curious, open the one that indicates as C / C ++ source code processors and you will see something like this,

Surprised? Well, let's continue, there is almost nothing left.

The previous C code should have been passed to a plain text editor and saved to disk with the extension .c Now we open PoEdit and go to File -> New Catalog. A dialog box will appear where to put the name of the project, Team ... (see the PoEdit tutorial that we already published)

In the Folders tab you indicate in the directory where the root directory of your translations is located and in folders the one in which you are going to locate the translation files of a set of programs, HTML files, etc. (This set is what is called a catalog). If you want to match the root directory with the catalog folder, you only have to put a period.

You accept and the following dialog will appear,

Where you choose the name that you will give to your .po file and the location in the file system (in our example / home / user / Translations). And once you click Save, this comforting screen will appear:

Great, right? . Well, we accept and we finally get to the editing and string translation screen:

And that's it. To translate!


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Heritage said

    I recommend https://poeditor.com as a better alternative to Poedit. It is an online tool, with a very useful interface and translation memory. It also has APIs and several useful plugins.

  2.   Nucleorion said

    But once we have the .po and .mo file, how do we get them to load, or the user can choose between the original or the translated one?