Make WordPress Core

Ticket #26638: 26638.patch

File 26638.patch, 2.5 KB (added by SergeyBiryukov, 10 years ago)
  • wp-includes/l10n.php

     
    7171 * @return string Translated text
    7272 */
    7373function translate( $text, $domain = 'default' ) {
    74         $translations = get_translations_for_domain( $domain );
    75         $translations = $translations->translate( $text );
     74        if ( is_textdomain_loaded( $domain ) ) {
     75                $translations = get_translations_for_domain( $domain );
     76                $translations = $translations->translate( $text );
     77        } else {
     78                $translations = $text;
     79        }
     80
    7681        /**
    7782         * Filter text with its translation.
    7883         *
     
    118123 * @return string Translated text on success, original text on failure.
    119124 */
    120125function translate_with_gettext_context( $text, $context, $domain = 'default' ) {
    121         $translations = get_translations_for_domain( $domain );
    122         $translations = $translations->translate( $text, $context );
     126        if ( is_textdomain_loaded( $domain ) ) {
     127                $translations = get_translations_for_domain( $domain );
     128                $translations = $translations->translate( $text, $context );
     129        } else {
     130                $translations = $text;
     131        }
     132
    123133        /**
    124134         * Filter text with its translation based on context information.
    125135         *
     
    295305 * @return string Either $single or $plural translated text.
    296306 */
    297307function _n( $single, $plural, $number, $domain = 'default' ) {
    298         $translations = get_translations_for_domain( $domain );
    299         $translation = $translations->translate_plural( $single, $plural, $number );
     308        if ( is_textdomain_loaded( $domain ) ) {
     309                $translations = get_translations_for_domain( $domain );
     310                $translation = $translations->translate_plural( $single, $plural, $number );
     311        } else {
     312                $translation = ( 1 == $number ) ? $single : $plural;
     313        }
     314
    300315        /**
    301316         * Filter text with its translation when plural option is available.
    302317         *
     
    326341 * @return string Either $single or $plural translated text with context.
    327342 */
    328343function _nx($single, $plural, $number, $context, $domain = 'default') {
    329         $translations = get_translations_for_domain( $domain );
    330         $translation = $translations->translate_plural( $single, $plural, $number, $context );
     344        if ( is_textdomain_loaded( $domain ) ) {
     345                $translations = get_translations_for_domain( $domain );
     346                $translation = $translations->translate_plural( $single, $plural, $number, $context );
     347        } else {
     348                $translation = ( 1 == $number ) ? $single : $plural;
     349        }
     350
    331351        /**
    332352         * Filter text with its translation while plural option and context are available.
    333353         *