2 function get_locale() {
6 return apply_filters( 'locale', $locale );
8 // WPLANG is defined in wp-config.
15 $locale = apply_filters('locale', $locale);
20 function translate($text, $domain) {
23 if (isset($l10n[$domain]))
24 return apply_filters('gettext', $l10n[$domain]->translate($text), $text);
29 // Return a translated string.
30 function __($text, $domain = 'default') {
31 return translate($text, $domain);
34 // Echo a translated string.
35 function _e($text, $domain = 'default') {
36 echo translate($text, $domain);
39 function _c($text, $domain = 'default') {
40 $whole = translate($text, $domain);
41 $last_bar = strrpos($whole, '|');
42 if ( false == $last_bar ) {
45 return substr($whole, 0, $last_bar);
49 // Return the plural form.
50 function __ngettext($single, $plural, $number, $domain = 'default') {
53 if (isset($l10n[$domain])) {
54 return apply_filters('ngettext', $l10n[$domain]->ngettext($single, $plural, $number), $single, $plural, $number);
63 function load_textdomain($domain, $mofile) {
66 if (isset($l10n[$domain]))
69 if ( is_readable($mofile))
70 $input = new CachedFileReader($mofile);
74 $l10n[$domain] = new gettext_reader($input);
77 function load_default_textdomain() {
80 $locale = get_locale();
84 $mofile = ABSPATH . LANGDIR . "/$locale.mo";
86 load_textdomain('default', $mofile);
89 function load_plugin_textdomain($domain, $path = false) {
90 $locale = get_locale();
94 if ( false === $path )
97 $mofile = ABSPATH . "$path/$domain-$locale.mo";
98 load_textdomain($domain, $mofile);
101 function load_theme_textdomain($domain) {
102 $locale = get_locale();
103 if ( empty($locale) )
106 $mofile = get_template_directory() . "/$locale.mo";
107 load_textdomain($domain, $mofile);