Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to translate this plugin. This plugin already has translations to some languages, and it has .pot file for adding new languages (as far as I understood from description). Although I never had an experience to work with .po .mo
So I wonder what are the main points. How to create .po .mo files and how to define that the plugin will talk a certain language, I tried to define for examble russian language, but did not find where to do this [I tried to insert define ('WPLANG', 'ru_RU'); in wp-config.php but it does not help].

share|improve this question

5 Answers 5

up vote 9 down vote accepted

The Editor

There are others, but this is most used: Poedit, a cross-platform gettext catalogs (.po files) editor.

The Formats

  • .mo stands for Machine Object
    -- compiled export of the .po file which is used by WordPress
  • .po stands for Portable Object
    -- editable text file with the translations strings
    -- based on the master .pot file, using Update from POT file PoEdit function
    -- some folks distribute this as a master file, but it should be used only for translations
  • .pot stands for Portable Object Template
    -- editable text file used to grab all the translatable strings from WordPress itself and Themes and Plugins, using Update from Sources PoEdit function

The Procedure

  • Duplicate the .pot file and rename it to plugin-basename-lang_COUNTRY.po
  • Example for the referenced plugin case: subscribe-reloaded-pt_BR.po
    -- pt_BR means Portuguese Brazil, but many languages don't have a country variation...
    -- you'll have to fill in with your own language
  • WPLANG in wp-config.php file must be set to your language, e.g., pt_BR
  • Every time you save the .po file, PoEdit automatically generates a .mo file, which is the one WordPress uses and basically the only one you need to upload

Observations

  • If you do a full or a decent partial translation, submit it to the plugin author so he can include it in the Repository and you get credited for it
  • Don't forget to make a backup of your translation, because if you upgrade the plugin your file will be lost
  • @user17078 plugin suggestion is quite nice, but I never used it much
  • I left the writing of this answer opened for a while and @Pippin answered in the interim, but am publishing anyway... :)
share|improve this answer

You can try this codestyling-localization plugin:. You can translate you plugins and themes using this.

share|improve this answer
1  
This is the best translation plugin I have ever seen. This plugin can own poedit anyday and the best part is that it is free and user-friendly. This answer should be voted up atleast. –  noc2spam Oct 2 at 9:37

I suggest also http://poeditor.com/. It is a web-based translation tool that works great with .po, .mo, .pot and other types of files.

share|improve this answer
    
A visitor proposed an edit pointing to a new plugin for this service: wordpress.org/extend/plugins/poeditor –  brasofilo May 17 '13 at 7:33

(Here is an EXAMPLE of translation to DEUTSCH. CHANGE the customs to YOUR DESIRED ones.)

in every plugins head, there is an unique name. (for example:

/*
Plugin Name: my-pluginname
.......
*/

then, in that plugin's folder, create a folder "languages";

then, into your plugin .php file (somewhere in the top), insert the initialization code:

class load_language 
{
    public function __construct()
    {
    add_action('init', array($this, 'load_my_transl'));
    }

     public function load_my_transl()
    {
        load_plugin_textdomain('my-pluginname', FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
    }
}

$zzzz = new load_language;

then open any text editor, then insert like this code (NOTE, THAT we are only adding two sample messages, "hello" and "bye", so , you can ADD AS MANY messages AS YOU WANT with the similar lines).

# English translations for PACKAGE package.
# Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# Automatically generated, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: my-pluginname 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-08-06 13:46-0400\n"
"PO-Revision-Date: 2013-03-21 11:20+0400\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"X-Poedit-SourceCharset: iso-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.5.4\n"


#: mypluginindex.php:87 (it is just a line of a note, to remind where our code appears)
msgid "mymessage1"
msgstr "Hello"

#: mypluginindex.php:88
msgid "mymessage2"
msgstr "Bye"

then save this file as "my-pluginname-en_US.po" (note, that .po is an extension of file, so check that your text editor program has not saved to "my-pluginname-en_US.po.TXT").

then download POEDIT software, and open this file. then edit the "translation" field, and then save as "my-pluginname-de_DE" there will be generated two files ( If poEdit does not generate the second .mo file automatically, just go to File -> Preferences -> Editor and check the box that says "Automatically compile .mo file on save"),

then put those two file into "languages" folder.

after this, open wp-config.php and find this code:

define ('WPLANG, '');

and change to

define ('WPLANG, 'de_DE');

That's all. When WordPress is loaded, it will read your plugins language file, with prefix -de_DE.

So, in the plugin's .php file, instead of:

echo "Something string";

you should use:

echo __("mymessage1", 'my-pluginname');



Finished. Now you should test your plugin.

p.s. used links:

share|improve this answer
    
I tried this with my theme. In header.php, I have echo __("thanks-for-visiting", 'transparent');. In theme\languages\transparent-en_US.po, I have msgid "thanks-for-visiting" msgstr "Hello! Thank you for visiting. Take a look around and subscribe to the ". This outputs "thanks-for-visiting" on the front end. –  Steve Mar 10 at 6:09
    
Thanks for the example. Very clear. –  Manolo Aug 14 at 17:06

You will want to use POEdit. It's a free application for creating .po/.mo files.

I wrote a pretty in-depth tutorial on the entire topic here. You can skip to Step 3 - Create the Translation File For Text Domain.

share|improve this answer

protected by Community Jun 26 at 18:41

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.