Home » Php » php – WordPress custom plugin language file loading / load_plugin_textdomain

php – WordPress custom plugin language file loading / load_plugin_textdomain

Posted by: admin February 25, 2020 Leave a comment

Questions:

I know this has been addressed several times already but all the solutions here didn´t help me.

I tried to add variable language strings, so I can translate my plugin afterwards.

the path / file structure is

custom-product
custom-product/languages

custom-product/languages/custom-product-en_EN.mo

custom-product/languages/custom-product-en_EN.po

custom-product/languages/custom-product-de_de.mo

custom-product/languages/custom-product-de_de.po

custom-product/index.php

<?php
/*
Plugin Name: Woocommerce Custom-Product Plugin
Plugin URI: 
Description: 
Version: 1.0.0
Author: Nan
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
WC tested up to: 3.9.2
*/


ob_start();
define('CUSTOM_PRODUCT', 'Custom Product');
define('TEXTAREA', 0);

function my_plugin_init() {
  load_plugin_textdomain( 'custom-product', false, dirname(plugin_basename(__FILE__)) . '/languages' );
}
add_action('init', 'my_plugin_init');

within the index.php

<li class="custom_tab"><a href="#custom_tab_data"><?php __( 'ppp', 'custom-product' ) ?></a></li>

the language file (english version, german is same except for the naming and “Language: de\n”)

# WPML is a WordPress plugin that can turn any WordPress or WordPressMU site into a full featured multilingual content management system.
# https://wpml.org
msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Project-Id-Version: WPML_EXPORT\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: en\n"
"MIME-Version: 1.0\n"
"X-Generator: Poedit 2.3\n"

#
msgid "ppp"
msgstr "thisisjustatest"

The return of load_plugin_textdomain is true.
The plugin works with hardcoded text of course but that is not what I want.

Where is my mistake?

How to&Answers: