TinyMCE 4 plugins: cannot get tinymce.Editor.getLang () to work

I am currently switching the plugin from TinyMCE 3.x to the new version of TinyMCE 4.0.26. I ran into serious problems trying to internationalize my plugin shortcuts.

In my plugin.js, I download the language pack by calling

tinymce.PluginManager.requireLangPack('myplugin');

with my i18n langs / de.js file looking something like this:

tinyMCE.addI18n('de', {
  myplugin: {
    button : 'Link einf\u00FCgen/bearbeiten',
    title : 'Link einf\u00FCgen/bearbeiten'
  }
});

When I access the static context

tinymce.i18n.data.myplugin

I see that both buttons and the variable name are available.

PROBLEM:

When calling editor.getLang ('myplugin.button'), I get {# myplugin.button} instead of the corresponding variable value.

After a little study of the source code, I found out that he expects the language code to exist within tinyMCE.i18n.data ..... which is not available

getLang: function(name, defaultVal) {
            return (
                this.editorManager.i18n[(this.settings.language || 'en') + '.' + name] ||
                (defaultVal !== undefined ? defaultVal : '{#' + name + '}')
            );
        },

@see https://github.com/tinymce/tinymce/blob/4.0.26/js/tinymce/classes/Editor.js#L1105

- ? - TinyMCE ?

+4
3

, . , , , , .

, , TinyMCE 4.2.6.

, :

tinymce.addI18n('de_AT', {
  'Title': 'Titel',
  'Example plugin': 'Beispielplugin'
});
Hide result
  • ( ) de_AT TinyMCE :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <link rel="stylesheet" href="">
</head>
<body>
    <textarea name="test"></textarea>
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="tinymce/tinymce.min.js"></script>
    <script>
    jQuery(document).ready(function ($) {
        $('textarea').tinymce({
            theme: "modern",
            plugins: 'example',
            toolbar: 'example',
            language:'de_AT'
        });
    })
    </script>
</body>
</html>
Hide result

"" Beispielplugin

editor.getLang.

, . .

, @stackoverflow.

0

:

tinymce.EditorManager.i18n.data[ed.getParam('language') + '.myplugin_name']['my_key'];
0

I finally earned it, maybe it can help, it's 1 year though, but it can help others. Since the whole way of creating the plugin has changed from 3.X to 4.X, I added requireLangPack to my plugin in the wrong place.

I was doing:

tinymce.PluginManager.add('myplugin', function(editor, url) {
     tinymce.PluginManager.requireLangPack('myplugin');
     ...
});

When should it be:

tinymce.PluginManager.requireLangPack('myplugin');
tinymce.PluginManager.add('myplugin', function(editor, url) {

         ...
});

In addition, the way to access these variables was as follows:

editor.getLang("myplugin").title;

Instead

editor.getLang("myplugin.title");

Hope this works for other people under the same circumstances.

0
source

Source: https://habr.com/ru/post/1541123/


All Articles