Install gettext

  1. Use ‘apt’ command
    sudo apt install gettext
  2.  php souce file add ‘__( ) , _e() function
    • __(“Engish”, [‘plugin name’]) , It’s function return to ‘string’.
    • _e(“Engish”, [‘plugin name’]) , It’s function string  output to stdout.
    • The others, check gettext document.
  3. Make directory for interpreting  language.
    • Execute following command.
    sudo apt install gettext
    cd path/to/your-plugin
    xgettext -k"__" -k"_e" -k"_n" -o languages/{plugin-name}.pot `find {php file top directry} -name '*.php'`
    • -k option specified interpreting function, -o option for output file, find command for looking for ‘*.php’, show ‘man find’.
  4. Generate interpreting resource file.
    cd languages
    msginit --locale=ja_JP.UTF-8 --input={plugin-name}.pot --output={plugin-name}-ja.po
  5. Edit interpreting resource file .po.
    #: minimenu.php:3
    msgid "Top"
    msgstr "<Japaese>" <-- if interpret to Japaese, write Japaese Word.
  6. Genaraite .mo file.
    msgfmt -o {pluin-name}-ja.mo {plugin-name}-ja.po
  7. Language registration to WordPress
    • Add action ‘plugins_loaded’ to plugin function.php following function.
    function xxxxx_textdomain() {
    $dir = dirname(plugin_basename(__FILE__));
    $rt = load_plugin_textdomain('<plugin name>', false,
    $dir . '/languages' );
    }
    add_action('plugins_loaded', 'xxxxx_textdomain');