WP_Translation_File
- Since
- 6.5.0
- Source
wp-includes/l10n/class-wp-translation-file.php:15
Class WP_Translation_File.
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).
Properties · 6
$headersarray<string,protected- List of headers.
$parsedboolprotected- Whether file has been parsed.
$errorstring|nullprotected- Error information.
$filestringprotected- File name.
$entriesarray<string,protected- Translation entries.
$plural_formscallable|nullprotected- Plural forms function.
Methods · 14
- __construct()Constructor.
- create()Creates a new WP_Translation_File instance for a given file.
- transform()Creates a new WP_Translation_File instance for a given file.
- headers()Returns all headers.
- entries()Returns all entries.
- error()Returns the current error information.
- get_file()Returns the file name.
- translate()Translates a given string.
- get_plural_form()Returns the plural form for a given number.
- get_plural_expression_from_header()Returns the plural forms expression as a tuple.
- make_plural_form_function()Makes a function, which will return the right translation index, according to the plural forms header.
- import()Imports translations from another file.
- parse_file()Parses the file.
- export()Exports translation contents as a string.
Source code
abstract class WP_Translation_File { /** * List of headers. * * @since 6.5.0 * @var array<string, string> */ protected $headers = array(); /** * Whether file has been parsed. * * @since 6.5.0 * @var bool */ protected $parsed = false; /** * Error information. * * @since 6.5.0 * @var string|null Error message or null if no error. */ protected $error; /** * File name. * * @since 6.5.0 * @var string */ protected $file = ''; /** * Translation entries. * * @since 6.5.0 * @var array<string, string> */ protected $entries = array(); /** * Plural forms function. * * @since 6.5.0 * @var callable|null Plural forms. */ protected $plural_forms = null; /** * Constructor. * * @since 6.5.0 * * @param string $file File to load. */ protected function __construct( string $file ) { $this->file = $file; } /** * Creates a new WP_Translation_File instance for a given file. * * @since 6.5.0 * * @param string $file File name. * @param string|null $filetype Optional. File type. Default inferred from file name. * @return false|WP_Translation_File */ public static function create( string $file, ?string $filetype = null ) { if ( ! is_readable( $file ) ) { return false; } if ( null === $filetype ) { $pos = strrpos( $file, '.' ); if ( false !== $pos ) { $filetype = substr( $file, $pos + 1 ); } }Changelog
Introduced in 6.5.0. Unchanged from 6.7.7 through 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, 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.