Translating generic strings on page using Poedit (.po and .mo files)

What am I talking about? What are .mo and .po files?

I’l explain that based on a problem that needs a solution. Lets say we have a website written in english. On it we use some generic strings (e.g. “Last posts”, “Comments”, “Login”, “Archive for cathegory”, etc.) that we want to translate into specific language(s) on demand (e.g. click on specific button on the page). In case our website visitor speaks English, we want all this generic strings to be displayed in English. In case he speaks Slovenian, we’d like to have a a trigger (such as flag icon or button) on the page that can trigger translation commands so that all generic strings are shown in Slovenian language.

So, how will we translate all this generic strings? What if we want need translations for many languages? Translating all generic strings directly in code would have been waisting of time, when we can use a simpler sollution. In WordPress we can teach our site template machine to use specific .mo files, which is used as a dictionary for all generic strings. Therefore they can be simultaneously translated from default (English) language into desired language on demand. How this is done can be further read on page http://codex.wordpress.org/Translating_WordPress.

Great, now we can start translating. We will need Poedit, a simple program that enables us to make a .mo translation file(s). It can open file types .po and .pot. Let’s say we have a file TemplateDefaultEntries.po. In it there are all generic strings that we want to translate into many languages. We open this file in Poedit.

Poedit-example

Then we translate all strings into desired language (e.g. Slovenian), and export the results into file type .mo. Exported file must have a specific name which is understood by our website template machine. In WordPress, in principle it would be calledsl_SI.mo. When using WordPress, we can upload the file on our templates directory, eg. public_html/wordpress-directory/wp-content/themes/my-theme. If our template machine already knows how to use .mo files, we are done.

But… What if we get a template with .mo files and there is no .po file? Poedit can’t open .mo files. We can use a solution on the page http://tools.konstruktors.com/. It enables us to make a .mo file from .po file

   Send article as PDF   

One thought on “Translating generic strings on page using Poedit (.po and .mo files)”

Comments are closed.