WP_Translation_Controller::translate_plural()
Translates plurals.
Checks both singular+plural combinations as well as just singulars, in case the translation file does not store the plural.
Метод класса: WP_Translation_Controller{}
Хуков нет.
Возвращает
Строку|false
. Translation on success, false otherwise.
Использование
$WP_Translation_Controller = new WP_Translation_Controller(); $WP_Translation_Controller->translate_plural( $plurals, $number, $context, $textdomain, ?string $locale );
- $plurals(массив) (обязательный)
Pair of singular and plural translations.
-
0(строка)
Singular translation. - 1(строка)
Plural translation.
-
- $number(int) (обязательный)
- Number of items.
- $context(строка)
- Context for the string.
По умолчанию: empty string - $textdomain(строка)
- Text domain.
По умолчанию: 'default' - ?string $locale **
- -
По умолчанию: null
Список изменений
С версии 6.5.0 | Введена. |
Код WP_Translation_Controller::translate_plural() WP Translation Controller::translate plural WP 6.6.2
public function translate_plural( array $plurals, int $number, string $context = '', string $textdomain = 'default', ?string $locale = null ) { if ( '' !== $context ) { $context .= "\4"; } $text = implode( "\0", $plurals ); $translation = $this->locate_translation( "{$context}{$text}", $textdomain, $locale ); if ( false === $translation ) { $text = $plurals[0]; $translation = $this->locate_translation( "{$context}{$text}", $textdomain, $locale ); if ( false === $translation ) { return false; } } /** @var WP_Translation_File $source */ $source = $translation['source']; $num = $source->get_plural_form( $number ); // See \Translations::translate_plural(). return $translation['entries'][ $num ] ?? $translation['entries'][0]; }