Wordpress插件翻译,.PO和.MO文件的翻译不起作用

时间:2018-08-04 13:32:13

标签: php wordpress

我需要制作一个多语言的Wordpress插件,并且我已经研究出最好的方法显然是使用.PO和.MO文件,但是我已经进行了配置并且也没有加载翻译。该插件最初位于“ en_US”中,如果我将Wordpress语言更改为西班牙语,我想将其更改为“ es_ES”

这里是我的代码

DiBi-Bot /语言/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' );

?>

代码已简化,我的意思是,我删除了一些部分供您理解,但基本上,我在'dibibot_add_roles'函数中使用翻译的行与我在.PO文件中使用的行相对应。

1 个答案:

答案 0 :(得分:0)

请确保您的文件位于wp-content / languages / plugins / your-file中,并检查文件名以text-domain开头。