Problems with plugin translation in wodpress, translation with .po and .mo files does not work

0

I need to make a plugin in wordpress that is multilanguage and the truth that I have researched and apparently the best way is with po and mo files, but I already make the configurations and likewise, it does not load the translations. the plugin is originally in 'en_US' and I want to change it to 'es_ES' or just 'is' if I change the wordpress language

here my code

DiBi-Bot / languages / DiBi-Bot-es.po (I have a clone of this same one but with es-ES, just in case)

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__)                           );


// funcion de wordpress para cargar el text domain
add_action( 'plugins_loaded', 'dibibot_load_textdomain');
function dibibot_load_textdomain() {
    load_plugin_textdomain( 'DiBi-Bot', DIBIBOT_PLUGIN_PATH . 'languages/' );
}

// Quiero agregar estos roles de wordpress en ingles o espanol dependiendo del idioma de wordpress
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' );

?>

take into account that the code simplifies it, that is to say, it removes parts so that they could understand, but basically, the lines where I use the translation in the function of the ibibot_add_roles correspond as they are with the one I have in the PO

    
asked by Anthony Medina 04.08.2018 в 14:51
source

1 answer

0

I think the path could be wrong. Try this ...

function dibibot_load_textdomain() {
    load_plugin_textdomain( 'DiBi-Bot', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
    
answered by 10.08.2018 в 02:29