| Server IP : 219.234.31.115 / Your IP : 216.73.217.134 Web Server : Apache System : Linux ebs-140924 5.10.0-30-amd64 #1 SMP Debian 5.10.218-1 (2024-06-01) x86_64 User : vndaystarftp ( 67432) PHP Version : 7.3.33 Disable Function : link,symlink,passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server,pcntl_fork,pcntl_rfork MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/wwwroot/vndaystarftp/wwwroot/wp-content/plugins/wpml-string-translation/classes/MO/ |
Upload File : |
<?php
namespace WPML\ST\MO;
class Plural implements \IWPML_Backend_Action, \IWPML_Frontend_Action {
public function add_hooks() {
add_filter( 'ngettext', [ $this, 'handle_plural' ], 9, 5 );
add_filter( 'ngettext_with_context', [ $this, 'handle_plural_with_context' ], 9, 6 );
}
/**
* @param string $translation Translated text.
* @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural.
* @param string $number The number to compare against to use either the singular or plural form.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*
* @return string
*/
public function handle_plural( $translation, $single, $plural, $number, $domain ) {
return $this->get_translation( $translation, $single, $plural, $number, function ( $original ) use ( $domain ) {
return __( $original, $domain );
} );
}
/**
* @param string $translation Translated text.
* @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural.
* @param string $number The number to compare against to use either the singular or plural form.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*
* @return string
*/
public function handle_plural_with_context( $translation, $single, $plural, $number, $context, $domain ) {
return $this->get_translation( $translation, $single, $plural, $number,
function ( $original ) use ( $domain, $context ) {
return _x( $original, $context, $domain );
} );
}
private function get_translation( $translation, $single, $plural, $number, $callback ) {
$original = (int) $number === 1 ? $single : $plural;
$possible_translation = $callback( $original );
if ( $possible_translation !== $original ) {
return $possible_translation;
}
return $translation;
}
}