Translation_Entry

Encapsulates a single translatable string with its translations, metadata, and context.

Source: wp-includes/pomo/entry.php Since: 2.8.0

Properties

PropertyTypeDefaultDescription
$is_pluralboolfalseWhether the entry contains a plural form
$contextstring|nullnullContext string differentiating equal strings in different contexts
$singularstring|nullnullThe singular source string
$pluralstring|nullnullThe plural form of the source string
$translationsarrayarray()Translations of the string (index 0 = singular, 1+ = plural forms)
$translator_commentsstring''Comments left by translators
$extracted_commentsstring''Comments left by developers
$referencesarrayarray()Source code locations in path/file.php:linenum format
$flagsarrayarray()Flags like php-format

Note: The class uses #[AllowDynamicProperties] and will accept arbitrary properties via the constructor args.


Methods

__construct( $args = array() )

Since: 2.8.0

Creates a translation entry from an associative array. If singular is not set in $args, creates an empty entry (returns immediately). All keys in $args are assigned as properties. Sets $is_plural = true if plural is provided and truthy. Forces $translations, $references, and $flags to arrays.

Parameters:

ParameterTypeDescription
$argsarrayAssociative array with keys: singular, plural, translations, context, translator_comments, extracted_comments, references, flags

key()

Generates a unique lookup key for this entry.

Since: 2.8.0

Returns: string|false — The key, or false if $singular is null.

Key format:

  • Without context: singular (with rn and r normalized to n)
  • With context: contextx04singular (EOT character as separator, matching MO file format)

merge_with( &$other )

Merges another Translation_Entry into this one.

Since: 2.8.0

Parameters:

ParameterTypeDescription
$otherTranslation_EntryOther entry (passed by reference)

Behavior:

  • Merges $flags arrays (unique values)
  • Merges $references arrays (unique values)
  • Appends $extracted_comments if different

Translation_Entry( $args = array() ) (deprecated)

PHP4 constructor.

Since: 2.8.0 Deprecated: 5.4.0 — Use __construct() instead.