Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#32555 closed enhancement (fixed)

TinyMCE should have a lang attribute

Reported by: greglone's profile GregLone Owned by: iseulde's profile iseulde
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: TinyMCE Keywords: has-patch
Focuses: administration Cc:

Description

Hello.

When we use add_editor_style(), we try to reproduce front styles in the editor. But there's at least one CSS property that can't be reproduced right now, it's hyphens.
To work, this property needs a lang attribute on a wrapping tag somewhere.

So far I managed to add it by creating a TinyMCE plugin:

tinymce.PluginManager.add( "langattribute", function( editor ) {
	editor.on( "init", function() {
		if ( window.mejsL10n && window.mejsL10n.language ) {
			editor.getBody().setAttribute( "lang", window.mejsL10n.language );
		}
	} );
} );

It's a bit hacky because I use a MediaElement.js var but it works. I'm sure there's a better way though.

Attachments (2)

32555-preview.png (53.3 KB) - added by GregLone 11 years ago.
Preview before/after
32555.patch (1.0 KB) - added by iseulde 11 years ago.

Download all attachments as: .zip

Change History (9)

@GregLone
11 years ago

Preview before/after

#1 @iseulde
11 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Version 4.2.2 deleted

Can't we just take the lang attribute from the parent window? This should be the same as the front end.

#2 @GregLone
11 years ago

It should be the same, indeed.
At least until we can change the language in the administration area.

So, I was just thinking, perhaps we should try to be forward-compatible:
Some JavaScript variables are printed in admin-header.php:

var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
	pagenow = '<?php echo $current_screen->id; ?>',
	typenow = '<?php echo $current_screen->post_type; ?>',
	adminpage = '<?php echo $admin_body_class; ?>',
	thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
	decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
	isRtl = <?php echo (int) is_rtl(); ?>;

Perhaps we could add a locale variable (fr_FR) and a language variable (fr-FR)?

	locale = '<?php echo apply_filters( 'content_locale', get_locale() ); ?>',
	language = '<?php echo apply_filters( 'content_language', get_bloginfo( 'language' ) ); ?>',

In this case, the MCE plugin is a bit simpler:

tinymce.PluginManager.add( "langattribute", function( editor ) {
	editor.on( "init", function() {
		editor.getBody().setAttribute( "lang", window.language );
	} );
} );

I guess we'll still need some changes if some day we can have a different language in the administration area (can't find the related ticket) but it's start.

#3 @anasr
11 years ago

Something like this I think:
http://richstyle.org/media/rsTinyMCE.png
(En in the third line).

@iseulde
11 years ago

#4 @iseulde
11 years ago

  • Keywords has-patch added

#5 @iseulde
11 years ago

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

In 35217:

TinyMCE: add lang attribute

This is needed to make hyphens: auto; work correctly.

Fixes #32555.

#6 @GregLone
11 years ago

Thank you @iseulde :)

#7 @netweb
11 years ago

  • Milestone changed from Future Release to 4.4
Note: See TracTickets for help on using tickets.