#32555 closed enhancement (fixed)
TinyMCE should have a lang attribute
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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)
Change History (9)
#1
@
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
@
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.

Preview before/after