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

Revision 2454, 1.8 kB (checked in by ryan, 4 years ago)

Fix fallback case for ngettext(). http://mosquito.wordpress.org/view.php?id=1125

  • 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     
19     if (empty($locale)) {
20     $locale = 'en_US';
21     }
22
23     $locale = apply_filters('locale', $locale);
24
25     return $locale;
26 }
27
28 // Return a translated string.   
29 function __($text, $domain = 'default') {
30     global $l10n;
31
32     if (isset($l10n[$domain])) {
33         return $l10n[$domain]->translate($text);
34     } else {
35         return $text;
36     }
37 }
38
39 // Echo a translated string.
40 function _e($text, $domain = 'default') {
41     global $l10n;
42
43     if (isset($l10n[$domain])) {
44         echo $l10n[$domain]->translate($text);
45     } else {
46         echo $text;
47     }
48 }
49
50 // Return the plural form.
51 function __ngettext($single, $plural, $number, $domain = 'default') {
52     global $l10n;
53
54     if (isset($l10n[$domain])) {
55         return $l10n[$domain]->ngettext($single, $plural, $number);
56     } else {
57         if ($number != 1)
58             return $plural;
59         else
60             return $single;
61     }
62 }
63
64 function load_textdomain($domain, $mofile) {
65     global $l10n;
66
67     if (isset($l10n[$domain])) {
68         return;
69     }
70
71     if ( is_readable($mofile)) {
72     $input = new CachedFileReader($mofile);
73     }    else {
74         return;
75     }
76
77     $l10n[$domain] = new gettext_reader($input);
78 }
79
80 function load_default_textdomain() {
81     global $l10n;
82
83     $locale = get_locale();
84     $mofile = ABSPATH . "wp-includes/languages/$locale.mo";
85     
86     load_textdomain('default', $mofile);
87 }
88
89 function load_plugin_textdomain($domain) {
90     $locale = get_locale();
91     
92     $mofile = ABSPATH . "wp-content/plugins/$domain-$locale.mo";
93     load_textdomain($domain, $mofile);
94 }
95
96 function load_theme_textdomain($domain) {
97     $locale = get_locale();
98     
99     $mofile = get_template_directory() . "/$locale.mo";
100     load_textdomain($domain, $mofile);
101 }
102
103 ?>
Note: See TracBrowser for help on using the browser.