wppaste
WordPress

_WP_Editors::wp_mce_translation( string $mce_locale = '', bool $json_only = false ): string

Since
3.9.0
Source
wp-includes/class-wp-editor.php:1466
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.

Compatibility

WordPress
since 3.9.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$mce_localestringoptional
The locale used for the editor.Default: ''
$json_onlybooloptional
Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone(). Default false.Default: false

Return value

string
Translation object, JSON encoded.

Performance profile

How much work a call to _WP_Editors::wp_mce_translation() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
24–45

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 71.

Plugin surface
1 hook

Third-party callbacks on 'wp_mce_translation' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost _WP_Editors::wp_mce_translation() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always24–28::get_translation(), apply_filters(), is_rtl(), wp_json_encode()
always27–31::get_mce_locale(), ::get_translation(), apply_filters(), is_rtl(), wp_json_encode()
always38–42::get_translation(), apply_filters(), is_rtl(), ::get_baseurl(), wp_json_encode()
always41–45::get_mce_locale(), ::get_translation(), apply_filters(), is_rtl(), ::get_baseurl(), wp_json_encode()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7124–4510
8.57124–4510
8.47124–45103 fewer instructions than PHP 8.3
8.37424–4510
8.27424–4510
8.17424–4510
7.47424–4510

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while _WP_Editors::wp_mce_translation() runs, in this order:

  1. apply_filters( wp_mce_translation )filterline 1487 (+21 into the body)

    Filters translated strings prepared for TinyMCE.

Uses · 7

Used by · 1

Source code

	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 ( str_contains( $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";	}

Changelog

Introduced in 3.9.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-editor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.