WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#15102 closed defect (bug) (worksforme)

tinymce language texts not loaded on page edit

Reported by: nb000 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.1
Component: TinyMCE Keywords: reporter-feedback
Focuses: Cc:

Description

On admin pages the TinyMCE texts are not translated.
E.g.: in Visual mode if you hover a any button,
you see a text, something like: advanced.bold_desc

If the page is opened up in Visual editing mode,
we get a javascript error.
Google Chrome: Cannot call method 'getLang' of null
Firebug: a is null

The bad file is wp-tinymce.js
(compressed in wp-tinymce.js.gz, read by wp-tinymce.php, line: 24)

the code sniplet that throws the error:
title:a.getLang("wpeditimage.edit_img")

I have tried to replace the function call with a title
(there were only 4 instaces of this call),
but then the editor did not let me
switch between Visual and Html mode.

The file to attach is a screen-shot
with Google Chrome's debugger opened showing the error.

Have a nice day.

Attachments (3)

screenshot.png (171.2 KB) - added by nb000 5 years ago.
debugger of Google Chrome showing the javascript bug
wp-langs-hu-from-src.js (13.1 KB) - added by nb000 5 years ago.
the hungarian language strings from a javascript block from a page source
wp-editimage.patch (11.2 KB) - added by azaozz 5 years ago.

Download all attachments as: .zip

Change History (16)

@nb0005 years ago

debugger of Google Chrome showing the javascript bug

comment:1 @azaozz5 years ago

  • Keywords reporter-feedback added; tinymce language getLang removed

The translated string for wpeditimage.edit_img is generated on line 421 in langs/wp-langs.php. Could you look at the source of the Edit Post page, all translated strings should be in a JS block near the end there and confirm that all are present (compare with wp-langs.php or wp-langs-en.js).

comment:2 @nb0005 years ago

I have checked the source code.
All hungarian language strings are there.
I will attach the file "wp-langs-hu-from-src.js"
which contains the javascript code block with the language strings
copied from the page source.
It matches the "wp-langs-en.js" file line-by-line (only the text value are different).
Any other ideas?

@nb0005 years ago

the hungarian language strings from a javascript block from a page source

comment:3 follow-up: @azaozz5 years ago

Just checked the uploaded file and the Hungarian translation and all strings are loading properly here. The JS error means that the string wpeditimage.edit_img is not loaded into TinyMCE i.e. wpeditimage = null.

You can check for the existence of that in the DOM inspector, go to tinyMCE => i18n object, it should contain all translated strings. Also check if that JS block is recognized and loaded properly. It should appear in the list of scripts for the page (in the debug tools/Firebug).

It is possible that PHP reaches some kind of limit while outputting the translated strings, but if it was running out of memory you wouldn't have seen the whole JS block in the source.

comment:4 in reply to: ↑ 3 ; follow-up: @nb0005 years ago

Replying to azaozz:

The JS error means that the string wpeditimage.edit_img
is not loaded into TinyMCE i.e. wpeditimage = null.

No, you are wrong here.
The JS error means, that a is null,
therefore it has no method getLang() which could be called.
The variable a is initiated as follows:
a = tinyMCE.activeEditor
Here is the problem that should be fixed:
at the time the language string is being loaded
in wp-tinymce.php (-> wp-tinymce.js.gz -> wp-tinymce.js)
the tinyMCE has no active editor, it is only created later.

You can check for the existence of that in the DOM inspector,
go to tinyMCE => i18n object, it should contain all translated strings.

I checked it in firebug.
When the tinyMCE.addI18n is called with the hungarian strings,
the tinyMCE.i18n contains the hungarian strings.
But when the page finishes loading the hungarian strings are gone,
and the english strings are loaded,
which are not used, since in tinyMCEPreInit mceInit { ..., language:"hu", ... }

Also check if that JS block is recognized and loaded properly.

Yes it works.
I put a breakpoint and saw the hungarian strings in the tinyMCE.i18n object.

It should appear in the list of scripts for the page (in the debug tools/Firebug).

Wrong again.
Firebug and the other debuggers do not list the scripts from a html source separately,
you only see that post.php has some scripts
(you can see the full html code including all inline scripts).

It is possible that PHP reaches some kind of limit while outputting the translated strings, but if it was running out of memory you wouldn't have seen the whole JS block in the source.

I agree, the problem is not PHP related.

comment:5 in reply to: ↑ 4 @azaozz5 years ago

Replying to nb000:
...

The JS error means, that a is null,
therefore it has no method getLang() which could be called.
The variable a is initiated as follows:
a = tinyMCE.activeEditor
Here is the problem that should be fixed:
at the time the language string is being loaded
in wp-tinymce.php (-> wp-tinymce.js.gz -> wp-tinymce.js)
the tinyMCE has no active editor, it is only created later.

This is controlled by the internal loading order in TinyMCE. All plugins are initiated after the core editor is ready.

...
When the tinyMCE.addI18n is called with the hungarian strings,
the tinyMCE.i18n contains the hungarian strings.
But when the page finishes loading the hungarian strings are gone,
and the english strings are loaded...

This sounds like TinyMCE is being initialized twice on the same textarea. Do you use any plugins that may be doing this?

I'm uploading a patch that replaces a = tinyMCE.activeEditor with a reference to the current editor instance when loading translations. As far as I remember this had some issues in the previous version, seems to work properly now.

@azaozz5 years ago

comment:6 follow-up: @azaozz5 years ago

To test the above patch you'll need to add define('SCRIPT_DEBUG', true); to wp-config.php.

comment:7 in reply to: ↑ 6 @nb0005 years ago

To test the above patch you'll need to add define('SCRIPT_DEBUG', true); to wp-config.php.

I added the define and patched the 2 javascript files.
Now I get the same error in another file (tinymce/plugins/wpgallery/editor_plugin.js).
Do I have to patch all editor_plugin.js files?

comment:8 @azaozz5 years ago

This confirms the assumption that TinyMCE is not initializing properly for some reason. All the a = tinyMCE.activeEditor vars are set after the editor has finished loading i.e. has all the translation strings already set. There are many places in the plugins where this is used.

Do you have two editors on the same page? And if yes, do you initialize the second editor after the default one is ready?

comment:9 @nb0004 years ago

I am using only one tinyMCE for editing the post.
But I figured out, that there are two "tinyMCE.init" line in the code.
I am investigating the cause right now...

comment:10 @nb0004 years ago

OK, I have it. I used a plugin, which made a call: wp_tiny_mce()
on all page, not just on it's on admin pages.
Thanks for the help.

comment:11 @nb0004 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Everyone having the same problem (tinyMCE text not translated),
should search for "tinyMCE.init" in the source, and if there is more then one,
the cause is found...

comment:12 @scribu4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:13 @scribu4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.