63 * @param string $text Text to translate. |
63 * @param string $text Text to translate. |
64 * @param string $domain Domain to retrieve the translated text. |
64 * @param string $domain Domain to retrieve the translated text. |
65 * @return string Translated text |
65 * @return string Translated text |
66 */ |
66 */ |
67 function translate( $text, $domain = 'default' ) { |
67 function translate( $text, $domain = 'default' ) { |
68 $translations = &get_translations_for_domain( $domain ); |
68 $translations = get_translations_for_domain( $domain ); |
69 return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain ); |
69 return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain ); |
70 } |
70 } |
71 |
71 |
72 function before_last_bar( $string ) { |
72 function before_last_bar( $string ) { |
73 $last_bar = strrpos( $string, '|' ); |
73 $last_bar = strrpos( $string, '|' ); |
76 else |
76 else |
77 return substr( $string, 0, $last_bar ); |
77 return substr( $string, 0, $last_bar ); |
78 } |
78 } |
79 |
79 |
80 function translate_with_gettext_context( $text, $context, $domain = 'default' ) { |
80 function translate_with_gettext_context( $text, $context, $domain = 'default' ) { |
81 $translations = &get_translations_for_domain( $domain ); |
81 $translations = get_translations_for_domain( $domain ); |
82 return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); |
82 return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); |
83 } |
83 } |
84 |
84 |
85 /** |
85 /** |
86 * Retrieves the translation of $text. If there is no translation, or |
86 * Retrieves the translation of $text. If there is no translation, or |
234 * @param int $number The number to compare against to use either $single or $plural |
234 * @param int $number The number to compare against to use either $single or $plural |
235 * @param string $domain Optional. The domain identifier the text should be retrieved in |
235 * @param string $domain Optional. The domain identifier the text should be retrieved in |
236 * @return string Either $single or $plural translated text |
236 * @return string Either $single or $plural translated text |
237 */ |
237 */ |
238 function _n( $single, $plural, $number, $domain = 'default' ) { |
238 function _n( $single, $plural, $number, $domain = 'default' ) { |
239 $translations = &get_translations_for_domain( $domain ); |
239 $translations = get_translations_for_domain( $domain ); |
240 $translation = $translations->translate_plural( $single, $plural, $number ); |
240 $translation = $translations->translate_plural( $single, $plural, $number ); |
241 return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); |
241 return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); |
242 } |
242 } |
243 |
243 |
244 /** |
244 /** |
247 * @see _n() |
247 * @see _n() |
248 * @see _x() |
248 * @see _x() |
249 * |
249 * |
250 */ |
250 */ |
251 function _nx($single, $plural, $number, $context, $domain = 'default') { |
251 function _nx($single, $plural, $number, $context, $domain = 'default') { |
252 $translations = &get_translations_for_domain( $domain ); |
252 $translations = get_translations_for_domain( $domain ); |
253 $translation = $translations->translate_plural( $single, $plural, $number, $context ); |
253 $translation = $translations->translate_plural( $single, $plural, $number, $context ); |
254 return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); |
254 return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); |
255 } |
255 } |
256 |
256 |
257 /** |
257 /** |
330 |
330 |
331 if ( true == $plugin_override ) { |
331 if ( true == $plugin_override ) { |
332 return true; |
332 return true; |
333 } |
333 } |
334 |
334 |
335 //print( $domain." ". $mofile."<br>"); |
|
336 do_action( 'load_textdomain', $domain, $mofile ); |
335 do_action( 'load_textdomain', $domain, $mofile ); |
337 |
336 |
338 $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); |
337 $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); |
339 |
338 |
340 if ( !is_readable( $mofile ) ) return false; |
339 if ( !is_readable( $mofile ) ) return false; |
458 * @param string $domain Unique identifier for retrieving translated strings |
457 * @param string $domain Unique identifier for retrieving translated strings |
459 */ |
458 */ |
460 function load_theme_textdomain( $domain, $path = false ) { |
459 function load_theme_textdomain( $domain, $path = false ) { |
461 $locale = apply_filters( 'theme_locale', get_locale(), $domain ); |
460 $locale = apply_filters( 'theme_locale', get_locale(), $domain ); |
462 |
461 |
463 $path = ( empty( $path ) ) ? get_template_directory() : $path; |
462 if ( ! $path ) |
464 |
463 $path = get_template_directory(); |
465 $mofile = "$path/$locale.mo"; |
464 |
|
465 // Load the textdomain from the Theme provided location, or theme directory first |
|
466 $mofile = "{$path}/{$locale}.mo"; |
|
467 if ( $loaded = load_textdomain($domain, $mofile) ) |
|
468 return $loaded; |
|
469 |
|
470 // Else, load textdomain from the Language directory |
|
471 $mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo"; |
466 return load_textdomain($domain, $mofile); |
472 return load_textdomain($domain, $mofile); |
467 } |
473 } |
468 |
474 |
469 /** |
475 /** |
470 * Loads the child themes translated strings. |
476 * Loads the child themes translated strings. |
477 * @since 2.9.0 |
483 * @since 2.9.0 |
478 * |
484 * |
479 * @param string $domain Unique identifier for retrieving translated strings |
485 * @param string $domain Unique identifier for retrieving translated strings |
480 */ |
486 */ |
481 function load_child_theme_textdomain( $domain, $path = false ) { |
487 function load_child_theme_textdomain( $domain, $path = false ) { |
482 $locale = apply_filters( 'theme_locale', get_locale(), $domain ); |
488 if ( ! $path ) |
483 |
489 $path = get_stylesheet_directory(); |
484 $path = ( empty( $path ) ) ? get_stylesheet_directory() : $path; |
490 return load_theme_textdomain( $domain, $path ); |
485 |
|
486 $mofile = "$path/$locale.mo"; |
|
487 return load_textdomain($domain, $mofile); |
|
488 } |
491 } |
489 |
492 |
490 /** |
493 /** |
491 * Returns the Translations instance for a domain. If there isn't one, |
494 * Returns the Translations instance for a domain. If there isn't one, |
492 * returns empty Translations instance. |
495 * returns empty Translations instance. |
493 * |
496 * |
494 * @param string $domain |
497 * @param string $domain |
495 * @return object A Translation instance |
498 * @return object A Translation instance |
496 */ |
499 */ |
497 function &get_translations_for_domain( $domain ) { |
500 function get_translations_for_domain( $domain ) { |
498 global $l10n; |
501 global $l10n; |
499 if ( !isset( $l10n[$domain] ) ) { |
502 if ( !isset( $l10n[$domain] ) ) { |
500 $l10n[$domain] = new NOOP_Translations; |
503 $l10n[$domain] = new NOOP_Translations; |
501 } |
504 } |
502 return $l10n[$domain]; |
505 return $l10n[$domain]; |