(THIS EXAMPLE IS A TRANSLATION WHICH YOU CAN CHANGE TRADITIONS FOR YOUR ART.)
Each plugin chapter has a unique name. (eg:
then in the plugin folder create the βLanguagesβ folder;
then, in your plugin's .php file (somewhere on top), paste 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 paste like this code (NOTE: The fact that we add only two examples of messages, "hello" and "bye", so that you can ADD AS MANY messages as YOU WANT with similar lines).
# English translations for PACKAGE package. # Copyright (C) 2012 THE PACKAGE 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 a file extension, so make sure your text editor program has not been saved to "my-pluginname-en_US.po.TXT").
then download the POEDIT software and open this file. then edit the "translation" field and then save it as "my-pluginname -de_DE", two files will be created (if poEdit does not create a second file .mo automatically, just go to "File" β "Settings" β "Editor" and install checkbox "Automatically compile .mo file when saving"),
then put these two files in the Languages ββfolder.
after that open wp-config.php and find this code:
define ('WPLANG, '');
and change to
define ('WPLANG, 'de_DE');
it's all. when wordperss loads, it will read your plugin language file with the -de_DE prefix.
therefore, in the plugin file.php instead:
echo "Something string";
you should use:
echo __("mymessage1", 'my-pluginname');
Finished. Now you should check your plugin.
psused links: https://codex.wordpress.org/I18n_for_WordPress_Developers
http://codex.wordpress.org/Translating_WordPress
https://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Installing_WordPress_in_Your_Language