wppaste
WordPress

WP_Translation_File_PHP

Since
6.5.0
Source
wp-includes/l10n/class-wp-translation-file-php.php:15
Class WP_Translation_File_PHP.

Compatibility

WordPress
since 6.5.0
  • 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).

Methods · 3

Source code

class WP_Translation_File_PHP extends WP_Translation_File {	/**	 * Parses the file.	 *	 * @since 6.5.0	 */	protected function parse_file() {		$this->parsed = true; 		$result = include $this->file;		if ( ! $result || ! is_array( $result ) ) {			$this->error = 'Invalid data';			return;		} 		if ( isset( $result['messages'] ) && is_array( $result['messages'] ) ) {			foreach ( $result['messages'] as $original => $translation ) {				$this->entries[ (string) $original ] = $translation;			}			unset( $result['messages'] );		} 		$this->headers = array_change_key_case( $result );	} 	/**	 * Exports translation contents as a string.	 *	 * @since 6.5.0	 *	 * @return string Translation file contents.	 */	public function export(): string {		$data = array_merge( $this->headers, array( 'messages' => $this->entries ) ); 		return '<?php' . PHP_EOL . 'return ' . $this->var_export( $data ) . ';' . PHP_EOL;	} 	/**	 * Outputs or returns a parsable string representation of a variable.	 *	 * Like {@see var_export()} but "minified", using short array syntax	 * and no newlines.	 *	 * @since 6.5.0	 *	 * @param mixed $value The variable you want to export.	 * @return string The variable representation.	 */	private function var_export( $value ): string {		if ( ! is_array( $value ) ) {			return var_export( $value, true );		} 		$entries = array(); 		$is_list = array_is_list( $value ); 		foreach ( $value as $key => $val ) {			$entries[] = $is_list ? $this->var_export( $val ) : var_export( $key, true ) . '=>' . $this->var_export( $val );		} 		return '[' . implode( ',', $entries ) . ']';	}}

Changelog

Introduced in 6.5.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.1.0 tag, from src/wp-includes/l10n/class-wp-translation-file-php.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.