#32555 closed enhancement (fixed)
TinyMCE should have a lang attribute
| Reported by: | GregLone | Owned by: | iseulde |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.4 |
| Component: | TinyMCE | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | administration |
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 Awaiting Review → Future Release
- Version 4.2.2
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)

Preview before/after