root/tags/1.3/wp-includes/l10n.php

Revision 972, 2.1 kB (checked in by donncha, 2 years ago)

WP Merge to rev 5499, this is a big one! Test it before you put it live!
Test only, not for production use yet

Line 
1 <?php
2 function get_locale() {
3     global $locale;
4
5     if (isset($locale))
6         return apply_filters( 'locale', $locale );
7
8     // WPLANG is defined in wp-config.
9     if (defined('WPLANG'))
10         $locale = WPLANG;
11
12     if (empty($locale))
13         $locale = '';
14
15     $locale = apply_filters('locale', $locale);
16
17     return $locale;
18 }
19
20 function translate($text, $domain) {
21     global $l10n;
22
23     if (isset($l10n[$domain]))
24         return apply_filters('gettext', $l10n[$domain]->translate($text), $text);
25     else
26         return $text;
27 }
28
29 // Return a translated string.
30 function __($text, $domain = 'default') {
31     return translate($text, $domain);
32 }
33
34 // Echo a translated string.
35 function _e($text, $domain = 'default') {
36     echo translate($text, $domain);
37 }
38
39 function _c($text, $domain = 'default') {
40     $whole = translate($text, $domain);
41     $last_bar = strrpos($whole, '|');
42     if ( false == $last_bar ) {
43         return $whole;
44     } else {
45         return substr($whole, 0, $last_bar);
46     }
47 }
48
49 // Return the plural form.
50 function __ngettext($single, $plural, $number, $domain = 'default') {
51     global $l10n;
52
53     if (isset($l10n[$domain])) {
54         return apply_filters('ngettext', $l10n[$domain]->ngettext($single, $plural, $number), $single, $plural, $number);
55     } else {
56         if ($number != 1)
57             return $plural;
58         else
59             return $single;
60     }
61 }
62
63 function load_textdomain($domain, $mofile) {
64     global $l10n;
65
66     if (isset($l10n[$domain]))
67         return;
68
69     if ( is_readable($mofile))
70         $input = new CachedFileReader($mofile);
71     else
72         return;
73
74     $l10n[$domain] = new gettext_reader($input);
75 }
76
77 function load_default_textdomain() {
78     global $l10n;
79
80     $locale = get_locale();
81     if ( empty($locale) )
82         $locale = 'en_US';
83
84     $mofile = ABSPATH . LANGDIR . "/$locale.mo";
85
86     load_textdomain('default', $mofile);
87 }
88
89 function load_plugin_textdomain($domain, $path = false) {
90     $locale = get_locale();
91     if ( empty($locale) )
92         $locale = 'en_US';
93
94     if ( false === $path )
95         $path = PLUGINDIR;
96
97     $mofile = ABSPATH . "$path/$domain-$locale.mo";
98     load_textdomain($domain, $mofile);
99 }
100
101 function load_theme_textdomain($domain) {
102     $locale = get_locale();
103     if ( empty($locale) )
104         $locale = 'en_US';
105
106     $mofile = get_template_directory() . "/$locale.mo";
107     load_textdomain($domain, $mofile);
108 }
109
110 ?>
111
Note: See TracBrowser for help on using the browser.