0
votes

I need to make a Wordpress plugin that is multilanguage and I have researched that apparently the best way is using .PO and .MO files, but I already make the configurations and also do not load the translations. The plugin is originally in 'en_US' and I want to change it to 'es_ES' if I change the Wordpress language to Spanish

here my code

DiBi-Bot/languages/DiBi-Bot-es-ES.po

msgid ""
msgstr ""
"Project-Id-Version: DiBi-Bot\n"
"POT-Creation-Date: 2018-08-03 15:59-0400\n"
"PO-Revision-Date: 2018-08-03 15:59-0400\n"
"Last-Translator: \n"
"Language-Team: dibibot.com\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.1.1\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-KeywordsList: __;_e;_n\n"
"X-Poedit-SearchPath-0: .\n"

#: dibi-bot.php:56
msgid "DibiBot User"
msgstr "Usuario de DibiBot"

#: dibi-bot.php:57
msgid "DibiBot Operator"
msgstr "Operador de DibiBot"

DiBi-Bot/dibi-bot.php


<?php
    /**
     *
     * @link              https://localhost/
     * @since             1.0.0
     * @package           DiBi-Bot
     *
     * @wordpress-plugin
     * Plugin Name:       DiBi-Bot
     * Plugin URI:        http://localhost
     * Description:       Chatbot de soporte a Clientes
     * Version:           1.0.0
     * Author:            Anthony Medina
     * Author URI:        https://localhost/
     * License:           Copyright 2019
     * License URI:       
     * Text Domain:       dibibot-plugin
     * Domain Path:       /languages/
     */

    if ( ! defined( 'ABSPATH' ) ) exit;

    define('DIBIBOT_PLUGIN_PATH' , plugin_dir_path(__FILE__)                           );

    add_action( 'plugins_loaded', 'dibibot_load_textdomain');
    function dibibot_load_textdomain() {
        load_plugin_textdomain( 'DiBi-Bot', DIBIBOT_PLUGIN_PATH . 'languages/' );
    }

    // I want to add these wordpress roles in English or Spanish depending on the wordpress language

    function dibibot_add_roles() {
        $subscriber = get_role('subscriber');
        add_role( 'dibibot_user', __('DibiBot User', 'DiBi-Bot'), $subscriber->capabilities );
        add_role( 'dibibot_operator', __('DibiBot Operator', 'DiBi-Bot'), $subscriber->capabilities );
    }

    // Activation and deactivaticion
    register_activation_hook( __FILE__, 'dibibot_add_roles' );

?>

The code is simplified, I mean, I removed parts for you to understand but basically, the lines where I use the translation in the 'dibibot_add_roles' function correspond with the lines I use in the .PO file

1

1 Answers

0
votes

Please Make sure that your file is in wp-content/languages/plugins/your-file and also check your file name starts with text-domain.