Below is a small tutorial of translation from English To German. (You can change the it as your needs).
in any plugin file, it has unique name in its header.
/*
Plugin Name: SampleTut
.......
*/
in that plugin folder, make a folder (named "languages");
into your plugin .php file (somewhere in top), insert this initialisation code:
class load_my_language
{
public function __construct()
{
add_action('init', array($this, 'load_translat'));
}
public function load_translal()
{
load_plugin_textdomain('SampleTut', FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
}
}
$ggg = new load_my_language ;
then open new text file and insert this code: (Now, we only make two messages, "helo" and "bye". You can insert as much as you need).
# 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: SampleTut 1.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-11-11 21:33-0400\n"
"PO-Revision-Date: 2013-11-21 12:33+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"
#: myplugininfile.php:47 (this is a note line)
msgid "mymessage1"
msgstr "Hello"
#: myplugininfile.php:48
msgid "mymessage2"
msgstr "Bye"
save this file and name it "SampleTut-en_US.po" (note, that .po should be an extension of the file, and not .po.txt)
download the software: POEDIT, and open that file and Press CTRL+S and thus, the program automatically generates the second functional .mo file ( If it doesnt generate the .mo file automatically, then edit preferences.); Then shutdown the program, and reopen the file again. Make your translations in "translation" fields, and after you finish, click SAVE AS and save the file as "SampleTut-de_DE" Now, the two German files will be generated.
then put those two English and two German files into "languages" folder.
Then, open wp-config.php and from default(English):
define ('WPLANG, '');
change to
define ('WPLANG, 'de_DE');
(This means, that we changed our wordpress main language. then worpdress will read our language file, with prefix -de_DE)
so, now open your plugin's .php file, and where you have any echo-ed word:
echo "Something";
change to :
echo __("mymessage1", 'SampleTut');
or the same as echo:
__e("mymessage1", 'SampleTut');
And thus, the wordpress shows you the appropriate translation for that id (mymessage1).
references:
codex.wordpress.org/I18n_for_WordPress_Developers
codex.wordpress.org/Translating_WordPress
codex.wordpress.org/Writing_a_Plugin
codex.wordpress.org/Installing_WordPress_in_Your_Language
echo __($string)
try its shorthand_e($string)
. More of these: codex.wordpress.org/L10n