在php文件中标记MCE按钮,所以我可以翻译它

问题描述 投票:0回答:1

我在我的wordpress自定义插件中使用自定义MCE按钮是我的代码

function enqueue_plugin_scripts($plugin_array)
{
//enqueue TinyMCE plugin script with its ID.
$plugin_array["related_post_button"] =  plugin_dir_url(__FILE__) . "index.js";
return $plugin_array;
}

add_filter("mce_external_plugins", "enqueue_plugin_scripts");

和js index.js是

(function() {
tinymce.create("tinymce.plugins.related_post_button", {

    //url argument holds the absolute url of our plugin directory
    init : function(ed, url) {

        //add new button     
        ed.addButton("related_btn", {
            title : "Add Related post shortcode",
            cmd : "related_command",
            icon: "custom-mce-icon",
        });

        //button functionality.
        ed.addCommand("related_command", function() {
            var selected_text = ed.selection.getContent();
            var return_text = selected_text + "[related]";
            ed.execCommand("mceInsertContent", 0, return_text);
        });

    },

    createControl : function(n, cm) {
        return null;
    },

    getInfo : function() {
        return {
            longname : "Extra Buttons",
            author : "Narayan Prusty",
            version : "1"
        };
    }
});

tinymce.PluginManager.add("related_post_button", tinymce.plugins.related_post_button);
})();

翻译我在php中使用此代码的任何内容

_e( "text to tranlate", 'wp-related-articles-acf' );

但是当我在index.js title : "Add Related post shortcode",中有代码时,我怎么能实现这一点

请注意一切都正确翻译,只是想知道我该如何实现

我已经尝试过https://codex.wordpress.org/Plugin_API/Filter_Reference/mce_external_languages但没有奏效

wordpress tinymce
1个回答
0
投票

TinyMCE有自己的语言文件,用于国际化UI:

https://www.tinymce.com/download/language-packages/

如果您的插件具有需要翻译的自定义文本,则需要将这些字符串添加到相应的语言文件中。要使用您的示例:

ed.addButton("related_btn", {
    title : "Add Related post shortcode",
    cmd : "related_command",
    icon: "custom-mce-icon",
});

文本Add Related post shortcode是语言文件中键/值对中的“键”。然后在每个语言文件中定义正确的字符串。例如,西班牙语文件可能如下所示:

tinymce.addI18n('es',{
    "Add Related post shortcode":"Añadir código breve de publicación relacionado",
    "Ok": "Ok",
    "Cancel": "Cancelar",
    .
    .
    .
});

注意:Wordpress通过一些TinyMCE API以稍微不同的方式做到这一点。请查看wp-langs-en.js目录中名为<wordpress_root>/wp-includes/js/tinymce/langs的文件,以获取他们如何设置英语的示例。您可以根据需要对其他语言执行相同操作。

© www.soinside.com 2019 - 2024. All rights reserved.