Home / APIs / _WP_Editors::wp_mce_translation() – Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n(), or as JS snippet that should run after tinymce.js is loaded.

Description

Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n(), or as JS snippet that should run after tinymce.js is loaded.

Usage

$string = _WP_Editors::wp_mce_translation( $mce_locale, $json_only );

Parameters

$mce_locale
( string ) optional – The locale used for the editor.
$json_only
( bool ) optional – optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().

Returns

string Translation object, JSON encoded.

Source

File name: wordpress/wp-includes/class-wp-editor.php
Lines: 1 to 49 of 49

  public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
    if ( ! $mce_locale ) {
      $mce_locale = self::get_mce_locale();
    }

    $mce_translation = self::get_translation();

    foreach ( $mce_translation as $name => $value ) {
      if ( is_array( $value ) ) {
        $mce_translation[$name] = $value[0];
      }
    }

    
/**
 * Filters translated strings prepared for TinyMCE.
 *
 * @since 3.9.0
 *
 * @param array  $mce_translation Key/value pairs of strings.
 * @param string $mce_locale      Locale.
 */
    $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );

    foreach ( $mce_translation as $key => $value ) {
      // Remove strings that are not translated.
      if ( $key === $value ) {
        unset( $mce_translation[$key] );
        continue;
      }

      if ( false !== strpos( $value, '&' ) ) {
        $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
      }
    }

    // Set direction
    if ( is_rtl() ) {
      $mce_translation['_dir'] = 'rtl';
    }

    if ( $json_only ) {
      return wp_json_encode( $mce_translation );
    }

    $baseurl = self::get_baseurl();

    return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
      "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
  }
 

 View on GitHub View on Trac

Called by

    Invoked by

      Calls

      1 to 2 of 2

      • apply_filters() – Call the functions added to a filter hook.
      • wp_json_encode() – Encode a variable into JSON, with some sanity checks.

      Call hooks

      1 to 1 of 1

      • wp_mce_translation – filter
      Function name: _WP_Editors::wp_mce_translation
      Class ref: _WP_Editors
      Plugin ref: WordPress
      Version: 4.9
      Sourcefile: wp-includes/class-wp-editor.php
      File ref: wp-includes/class-wp-editor.php
      API type: private
      Deprecated?: No
      API Letters: _,E,M,W

      Published: 12th March 2017 | Last updated: 8th June 2017

      Information

      Function name: _WP_Editors::wp_mce_translation
      Class ref: _WP_Editors
      Plugin ref: WordPress
      Version: 4.9
      Sourcefile: wp-includes/class-wp-editor.php
      File ref: wp-includes/class-wp-editor.php
      API type: private
      Deprecated?: No
      API Letters: _,E,M,W

      • Plugins
      • Themes
      • Shortcodes
      • APIs
      • Files
      • Hooks
      • Classes
      • Sites
      • Sitemap
      • Blog
      WooCommerce a2z WooCommerce a2z
      WooCommerce

      Site:  woocommerce.wp-a2z.org
      © Copyright WooCommerce a2z 2014-2018. All rights reserved.


      Website designed and developed by Herb Miller
      Proudly powered by WordPress and oik plugins