Make WordPress Core


Ignore:
Timestamp:
10/25/2016 01:39:15 AM (7 years ago)
Author:
azaozz
Message:

TinyMCE: make keyboard shortcuts more discoverable by adding them to the buttons tooltips and in the Formats drop-down.

Props mor10, azaozz.
Fixes #38063.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-editor.php

    r38803 r38897  
    2727    private static $drag_drop_upload = false;
    2828    private static $old_dfw_compat = false;
     29    private static $translation;
    2930
    3031    private function __construct() {}
     
    358359                $no_captions = (bool) apply_filters( 'disable_captions', '' );
    359360                $ext_plugins = '';
     361                $shortcut_labels = array();
     362
     363                foreach ( self::get_translation() as $name => $value ) {
     364                    if ( is_array( $value ) ) {
     365                        $shortcut_labels[$name] = $value[1];
     366                    }
     367                }
    360368
    361369                if ( $set['teeny'] ) {
     
    551559                    'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
    552560                    'plugins' => implode( ',', $plugins ),
    553                     'wp_lang_attr' => get_bloginfo( 'language' )
     561                    'wp_lang_attr' => get_bloginfo( 'language' ),
     562                    'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ),
    554563                );
    555564
     
    813822    }
    814823
    815     /**
    816      * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
    817      * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
    818      *
    819      * @static
    820      * @param string $mce_locale The locale used for the editor.
    821      * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
    822      * @return string Translation object, JSON encoded.
    823      */
    824     public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
    825 
    826         $mce_translation = array(
     824    private static function get_translation() {
     825        if ( empty( self::$translation ) ) {
     826            self::$translation = array(
    827827            // Default TinyMCE strings
    828828            'New document' => __( 'New document' ),
     
    830830
    831831            'Headings' => _x( 'Headings', 'TinyMCE' ),
    832             'Heading 1' => __( 'Heading 1' ),
    833             'Heading 2' => __( 'Heading 2' ),
    834             'Heading 3' => __( 'Heading 3' ),
    835             'Heading 4' => __( 'Heading 4' ),
    836             'Heading 5' => __( 'Heading 5' ),
    837             'Heading 6' => __( 'Heading 6' ),
     832            'Heading 1' => array( __( 'Heading 1' ), 'access1' ),
     833            'Heading 2' => array( __( 'Heading 2' ), 'access2' ),
     834            'Heading 3' => array( __( 'Heading 3' ), 'access3' ),
     835            'Heading 4' => array( __( 'Heading 4' ), 'access4' ),
     836            'Heading 5' => array( __( 'Heading 5' ), 'access5' ),
     837            'Heading 6' => array( __( 'Heading 6' ), 'access6' ),
    838838
    839839            /* translators: block tags */
    840840            'Blocks' => _x( 'Blocks', 'TinyMCE' ),
    841             'Paragraph' => __( 'Paragraph' ),
    842             'Blockquote' => __( 'Blockquote' ),
     841            'Paragraph' => array( __( 'Paragraph' ), 'access7' ),
     842            'Blockquote' => array( __( 'Blockquote' ), 'accessQ' ),
    843843            'Div' => _x( 'Div', 'HTML tag' ),
    844844            'Pre' => _x( 'Pre', 'HTML tag' ),
     
    847847
    848848            'Inline' => _x( 'Inline', 'HTML elements' ),
    849             'Underline' => __( 'Underline' ),
    850             'Strikethrough' => __( 'Strikethrough' ),
     849            'Underline' => array( __( 'Underline' ), 'metaU' ),
     850            'Strikethrough' => array( __( 'Strikethrough' ), 'accessD' ),
    851851            'Subscript' => __( 'Subscript' ),
    852852            'Superscript' => __( 'Superscript' ),
    853853            'Clear formatting' => __( 'Clear formatting' ),
    854             'Bold' => __( 'Bold' ),
    855             'Italic' => __( 'Italic' ),
    856             'Code' => __( 'Code' ),
     854            'Bold' => array( __( 'Bold' ), 'metaB' ),
     855            'Italic' => array( __( 'Italic' ), 'metaI' ),
     856            'Code' => array( __( 'Code' ), 'accessX' ),
    857857            'Source code' => __( 'Source code' ),
    858858            'Font Family' => __( 'Font Family' ),
    859859            'Font Sizes' => __( 'Font Sizes' ),
    860860
    861             'Align center' => __( 'Align center' ),
    862             'Align right' => __( 'Align right' ),
    863             'Align left' => __( 'Align left' ),
    864             'Justify' => __( 'Justify' ),
     861            'Align center' => array( __( 'Align center' ), 'accessC' ),
     862            'Align right' => array( __( 'Align right' ), 'accessR' ),
     863            'Align left' => array( __( 'Align left' ), 'accessL' ),
     864            'Justify' => array( __( 'Justify' ), 'accessJ' ),
    865865            'Increase indent' => __( 'Increase indent' ),
    866866            'Decrease indent' => __( 'Decrease indent' ),
    867867
    868             'Cut' => __( 'Cut' ),
    869             'Copy' => __( 'Copy' ),
    870             'Paste' => __( 'Paste' ),
    871             'Select all' => __( 'Select all' ),
    872             'Undo' => __( 'Undo' ),
    873             'Redo' => __( 'Redo' ),
     868            'Cut' => array( __( 'Cut' ), 'metaX' ),
     869            'Copy' => array( __( 'Copy' ), 'metaC' ),
     870            'Paste' => array( __( 'Paste' ), 'metaV' ),
     871            'Select all' => array( __( 'Select all' ), 'metaA' ),
     872            'Undo' => array( __( 'Undo' ), 'metaZ' ),
     873            'Redo' => array( __( 'Redo' ), 'metaY' ),
    874874
    875875            'Ok' => __( 'OK' ),
     
    878878            'Visual aids' => __( 'Visual aids' ),
    879879
    880             'Bullet list' => __( 'Bulleted list' ),
    881             'Numbered list' => __( 'Numbered list' ),
     880            'Bullet list' => array( __( 'Bulleted list' ), 'accessU' ),
     881            'Numbered list' => array( __( 'Numbered list' ), 'accessO' ),
    882882            'Square' => _x( 'Square', 'list style' ),
    883883            'Default' => _x( 'Default', 'list style' ),
     
    905905
    906906            // Media, image plugins
    907             'Insert/edit image' => __( 'Insert/edit image' ),
     907            'Insert/edit image' => array( __( 'Insert/edit image' ), 'accessM' ),
    908908            'General' => __( 'General' ),
    909909            'Advanced' => __( 'Advanced' ),
     
    939939            'Horizontal space' => __( 'Horizontal space' ),
    940940            'Restore last draft' => __( 'Restore last draft' ),
    941             'Insert/edit link' => __( 'Insert/edit link' ),
    942             'Remove link' => __( 'Remove link' ),
     941            'Insert/edit link' => array( __( 'Insert/edit link' ), 'metaK' ),
     942            'Remove link' => array( __( 'Remove link' ), 'accessS' ),
    943943
    944944            'Color' => __( 'Color' ),
     
    10441044
    10451045            // WordPress strings
    1046             'Toolbar Toggle' => __( 'Toolbar Toggle' ),
    1047             'Insert Read More tag' => __( 'Insert Read More tag' ),
    1048             'Insert Page Break tag' => __( 'Insert Page Break tag' ),
     1046            'Toolbar Toggle' => array( __( 'Toolbar Toggle' ), 'accessZ' ),
     1047            'Insert Read More tag' => array( __( 'Insert Read More tag' ), 'accessT' ),
     1048            'Insert Page Break tag' => array( __( 'Insert Page Break tag' ), 'accessP' ),
    10491049            'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor (no ellipsis)
    1050             'Distraction-free writing mode' => __( 'Distraction-free writing mode' ),
     1050            'Distraction-free writing mode' => array( __( 'Distraction-free writing mode' ), 'accessW' ),
    10511051            'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
    10521052            'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
     
    10571057
    10581058            // Shortcuts help modal
    1059             'Keyboard Shortcuts' => __( 'Keyboard Shortcuts' ),
     1059            'Keyboard Shortcuts' => array( __( 'Keyboard Shortcuts' ), 'accessH' ),
    10601060            'Default shortcuts,' => __( 'Default shortcuts,' ),
    10611061            'Additional shortcuts,' => __( 'Additional shortcuts,' ),
     
    10801080            'The next group of formatting shortcuts are applied as you type or when you insert them around plain text in the same paragraph. Press Escape or the Undo button to undo.' =>
    10811081                __( 'The next group of formatting shortcuts are applied as you type or when you insert them around plain text in the same paragraph. Press Escape or the Undo button to undo.' ),
    1082         );
     1082            );
     1083        }
    10831084
    10841085        /**
     
    10931094         */
    10941095
     1096        return self::$translation;
     1097    }
     1098
     1099    /**
     1100     * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
     1101     * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
     1102     *
     1103     * @static
     1104     * @param string $mce_locale The locale used for the editor.
     1105     * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
     1106     * @return string Translation object, JSON encoded.
     1107     */
     1108    public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
    10951109        if ( ! $mce_locale ) {
    10961110            $mce_locale = self::$mce_locale;
     1111        }
     1112
     1113        $mce_translation = self::get_translation();
     1114       
     1115        foreach ( $mce_translation as $name => $value ) {
     1116            if ( is_array( $value ) ) {
     1117                $mce_translation[$name] = $value[0];
     1118            }
    10971119        }
    10981120
Note: See TracChangeset for help on using the changeset viewer.