Internationalization: Not loading plugin translated text

I am trying to internationalize the plugin I am creating but it doesn’t seem to display the translated texts that are translated in the .po file.

Firstly, I have referred to the following sources:
https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/
https://www.sitepoint.com/wordpress-i18n-make-your-plugin-translation-ready/
https://premium.wpmudev.org/blog/ultimate-guide-wordpress-localization/#plugins

Here is my current directory like:

–my-custom-dragon-plugin
–my-custom-dragon-plugin.php
–languages
–my-custom-dragon-plugin-de_DE.mo
–my-custom-dragon-plugin-de_DE.po

Initially, my text domain was not the plugin slug (is it not possible to use a different text domain?) so I had to change it as per the second link I have posted, it mentioned:

The text domain must match the slug of the plugin. For example, if
your plugin is a single file called sample-plugin.php or it is
contained in a folder called sample-plugin the text domain should be
sample-plugin.

So in my php files I have something like __(‘Read More’, my-custom-dragon-plugin)

In my my-custom-dragon-plugin.php, I have the plugin definition and the function that loads the text domain:

/*
Plugin Name: My Custom Dragon
Plugin URI: https://www.xxxxxx.de/
Description: This is a plugin customized for my dragons.
Author: Jedragon
Text Domain: my-custom-dragon-plugin
Domain Path: /languages/
Version: 0.1.0
*/

add_action( ‘plugins_loaded’, ‘load_my_textdomain’ );

function load_my_textdomain() {

$domain = ‘my-custom-dragon-plugin’;
load_plugin_textdomain( $domain, false, dirname( plugin_basename( __FILE__ ) ) . ‘/languages/’ );

}

I am also using POEdit for my .po files.

When I try to check if the changes are reflected, the text still remains in English even if I change the site language.

Is there anything that I have missed or I am doing incorrectly?

Thanks in advance.

Read more here:: Internationalization: Not loading plugin translated text

Leave a Reply

Your email address will not be published. Required fields are marked *