File manager - Edit - /home2/ajansonline/public_html/l10n.zip
Back
PK ̛�Z�]N�� � class-wp-translations.phpnu �[��� <?php /** * I18N: WP_Translations class. * * @package WordPress * @subpackage I18N * @since 6.5.0 */ /** * Class WP_Translations. * * @since 6.5.0 * * @property-read array<string, string> $headers * @property-read array<string, string[]> $entries */ class WP_Translations { /** * Text domain. * * @since 6.5.0 * @var string */ protected $textdomain = 'default'; /** * Translation controller instance. * * @since 6.5.0 * @var WP_Translation_Controller */ protected $controller; /** * Constructor. * * @since 6.5.0 * * @param WP_Translation_Controller $controller I18N controller. * @param string $textdomain Optional. Text domain. Default 'default'. */ public function __construct( WP_Translation_Controller $controller, string $textdomain = 'default' ) { $this->controller = $controller; $this->textdomain = $textdomain; } /** * Magic getter for backward compatibility. * * @since 6.5.0 * * @param string $name Property name. * @return mixed */ public function __get( string $name ) { if ( 'entries' === $name ) { $entries = $this->controller->get_entries( $this->textdomain ); $result = array(); foreach ( $entries as $original => $translations ) { $result[] = $this->make_entry( $original, $translations ); } return $result; } if ( 'headers' === $name ) { return $this->controller->get_headers( $this->textdomain ); } return null; } /** * Builds a Translation_Entry from original string and translation strings. * * @see MO::make_entry() * * @since 6.5.0 * * @param string $original Original string to translate from MO file. Might contain * 0x04 as context separator or 0x00 as singular/plural separator. * @param string $translations Translation strings from MO file. * @return Translation_Entry Entry instance. */ private function make_entry( $original, $translations ): Translation_Entry { $entry = new Translation_Entry(); // Look for context, separated by \4. $parts = explode( "\4", $original ); if ( isset( $parts[1] ) ) { $original = $parts[1]; $entry->context = $parts[0]; } $entry->singular = $original; $entry->translations = explode( "\0", $translations ); $entry->is_plural = count( $entry->translations ) > 1; return $entry; } /** * Translates a plural string. * * @since 6.5.0 * * @param string|null $singular Singular string. * @param string|null $plural Plural string. * @param int|float $count Count. Should be an integer, but some plugins pass floats. * @param string|null $context Context. * @return string|null Translation if it exists, or the unchanged singular string. */ public function translate_plural( $singular, $plural, $count = 1, $context = '' ) { if ( null === $singular || null === $plural ) { return $singular; } $translation = $this->controller->translate_plural( array( $singular, $plural ), (int) $count, (string) $context, $this->textdomain ); if ( false !== $translation ) { return $translation; } // Fall back to the original with English grammar rules. return ( 1 === $count ? $singular : $plural ); } /** * Translates a singular string. * * @since 6.5.0 * * @param string|null $singular Singular string. * @param string|null $context Context. * @return string|null Translation if it exists, or the unchanged singular string */ public function translate( $singular, $context = '' ) { if ( null === $singular ) { return null; } $translation = $this->controller->translate( $singular, (string) $context, $this->textdomain ); if ( false !== $translation ) { return $translation; } // Fall back to the original. return $singular; } } PK ̛�ZAz�� � class-wp-translation-file.phpnu �[��� <?php /** * I18N: WP_Translation_File class. * * @package WordPress * @subpackage I18N * @since 6.5.0 */ /** * Class WP_Translation_File. * * @since 6.5.0 */ 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 ); } } switch ( $filetype ) { case 'mo': return new WP_Translation_File_MO( $file ); case 'php': return new WP_Translation_File_PHP( $file ); default: return false; } } /** * Creates a new WP_Translation_File instance for a given file. * * @since 6.5.0 * * @param string $file Source file name. * @param string $filetype Desired target file type. * @return string|false Transformed translation file contents on success, false otherwise. */ public static function transform( string $file, string $filetype ) { $source = self::create( $file ); if ( false === $source ) { return false; } switch ( $filetype ) { case 'mo': $destination = new WP_Translation_File_MO( '' ); break; case 'php': $destination = new WP_Translation_File_PHP( '' ); break; default: return false; } $success = $destination->import( $source ); if ( ! $success ) { return false; } return $destination->export(); } /** * Returns all headers. * * @since 6.5.0 * * @return array<string, string> Headers. */ public function headers(): array { if ( ! $this->parsed ) { $this->parse_file(); } return $this->headers; } /** * Returns all entries. * * @since 6.5.0 * * @return array<string, string[]> Entries. */ public function entries(): array { if ( ! $this->parsed ) { $this->parse_file(); } return $this->entries; } /** * Returns the current error information. * * @since 6.5.0 * * @return string|null Error message or null if no error. */ public function error() { return $this->error; } /** * Returns the file name. * * @since 6.5.0 * * @return string File name. */ public function get_file(): string { return $this->file; } /** * Translates a given string. * * @since 6.5.0 * * @param string $text String to translate. * @return false|string Translation(s) on success, false otherwise. */ public function translate( string $text ) { if ( ! $this->parsed ) { $this->parse_file(); } return $this->entries[ $text ] ?? false; } /** * Returns the plural form for a given number. * * @since 6.5.0 * * @param int $number Count. * @return int Plural form. */ public function get_plural_form( int $number ): int { if ( ! $this->parsed ) { $this->parse_file(); } if ( null === $this->plural_forms && isset( $this->headers['plural-forms'] ) ) { $expression = $this->get_plural_expression_from_header( $this->headers['plural-forms'] ); $this->plural_forms = $this->make_plural_form_function( $expression ); } if ( is_callable( $this->plural_forms ) ) { /** * Plural form. * * @var int $result Plural form. */ $result = call_user_func( $this->plural_forms, $number ); return $result; } // Default plural form matches English, only "One" is considered singular. return ( 1 === $number ? 0 : 1 ); } /** * Returns the plural forms expression as a tuple. * * @since 6.5.0 * * @param string $header Plural-Forms header string. * @return string Plural forms expression. */ protected function get_plural_expression_from_header( string $header ): string { if ( preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches ) ) { return trim( $matches[2] ); } return 'n != 1'; } /** * Makes a function, which will return the right translation index, according to the * plural forms header. * * @since 6.5.0 * * @param string $expression Plural form expression. * @return callable(int $num): int Plural forms function. */ protected function make_plural_form_function( string $expression ): callable { try { $handler = new Plural_Forms( rtrim( $expression, ';' ) ); return array( $handler, 'get' ); } catch ( Exception $e ) { // Fall back to default plural-form function. return $this->make_plural_form_function( 'n != 1' ); } } /** * Imports translations from another file. * * @since 6.5.0 * * @param WP_Translation_File $source Source file. * @return bool True on success, false otherwise. */ protected function import( WP_Translation_File $source ): bool { if ( null !== $source->error() ) { return false; } $this->headers = $source->headers(); $this->entries = $source->entries(); $this->error = $source->error(); return null === $this->error; } /** * Parses the file. * * @since 6.5.0 */ abstract protected function parse_file(); /** * Exports translation contents as a string. * * @since 6.5.0 * * @return string Translation file contents. */ abstract public function export(); } PK ̛�Z{V� ! class-wp-translation-file-php.phpnu �[��� <?php /** * I18N: WP_Translation_File_PHP class. * * @package WordPress * @subpackage I18N * @since 6.5.0 */ /** * Class WP_Translation_File_PHP. * * @since 6.5.0 */ 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 ) . ']'; } } PK ̛�Z "