root/branches/2.0/wp-includes/wp-l10n.php

Revision 3425, 1.9 kB (checked in by ryan, 3 years ago)

Add gettext filter. fixes #2258

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2
3 if ( defined('WPLANG') && '' != constant('WPLANG') ) {
4     include_once(ABSPATH . 'wp-includes/streams.php');
5     include_once(ABSPATH . 'wp-includes/gettext.php');
6 }
7
8 function get_locale() {
9     global $locale;
10
11     if (isset($locale))
12         return $locale;
13
14     // WPLANG is defined in wp-config.
15     if (defined('WPLANG'))
16         $locale = WPLANG;
17     
18     if (empty($locale))
19         $locale = 'en_US';
20
21     $locale = apply_filters('locale', $locale);
22
23     return $locale;
24 }
25
26 // Return a translated string.   
27 function __($text, $domain = 'default') {
28     global $l10n;
29
30     if (isset($l10n[$domain]))
31         return apply_filters('gettext', $l10n[$domain]->translate($text), $text);
32     else
33         return $text;
34 }
35
36 // Echo a translated string.
37 function _e($text, $domain = 'default') {
38     global $l10n;
39
40     if (isset($l10n[$domain]))
41         echo apply_filters('gettext', $l10n[$domain]->translate($text), $text);
42     else
43         echo $text;
44 }
45
46 // Return the plural form.
47 function __ngettext($single, $plural, $number, $domain = 'default') {
48     global $l10n;
49
50     if (isset($l10n[$domain])) {
51         return $l10n[$domain]->ngettext($single, $plural, $number);
52     } else {
53         if ($number != 1)
54             return $plural;
55         else
56             return $single;
57     }
58 }
59
60 function load_textdomain($domain, $mofile) {
61     global $l10n;
62
63     if (isset($l10n[$domain]))
64         return;
65
66     if ( is_readable($mofile))
67         $input = new CachedFileReader($mofile);
68     else
69         return;
70
71     $l10n[$domain] = new gettext_reader($input);
72 }
73
74 function load_default_textdomain() {
75     global $l10n;
76
77     $locale = get_locale();
78     $mofile = ABSPATH . "wp-includes/languages/$locale.mo";
79     
80     load_textdomain('default', $mofile);
81 }
82
83 function load_plugin_textdomain($domain, $path = 'wp-content/plugins') {
84     $locale = get_locale();
85     
86     $mofile = ABSPATH . "$path/$domain-$locale.mo";
87     load_textdomain($domain, $mofile);
88 }
89
90 function load_theme_textdomain($domain) {
91     $locale = get_locale();
92     
93     $mofile = get_template_directory() . "/$locale.mo";
94     load_textdomain($domain, $mofile);
95 }
96
97 ?>
Note: See TracBrowser for help on using the browser.