Plugin and theme localization.
git-svn-id: https://develop.svn.wordpress.org/trunk@1808 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
38f8395c4a
commit
e41ead7068
|
@ -29,24 +29,65 @@ if ( is_readable($mofile) && ($locale != 'en_US') ) {
|
|||
$input = false;
|
||||
}
|
||||
|
||||
$l10n = new gettext_reader($input);
|
||||
$l10n['default'] = new gettext_reader($input);
|
||||
|
||||
// Return a translated string.
|
||||
function __($text) {
|
||||
function __($text, $domain = 'default') {
|
||||
global $l10n;
|
||||
return $l10n->translate($text);
|
||||
|
||||
if (isset($l10n[$domain])) {
|
||||
return $l10n[$domain]->translate($text);
|
||||
} else {
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
// Echo a translated string.
|
||||
function _e($text) {
|
||||
function _e($text, $domain = 'default') {
|
||||
global $l10n;
|
||||
echo $l10n->translate($text);
|
||||
|
||||
if (isset($l10n[$domain])) {
|
||||
echo $l10n[$domain]->translate($text);
|
||||
} else {
|
||||
echo $text;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the plural form.
|
||||
function __ngettext($single, $plural, $number) {
|
||||
function __ngettext($single, $plural, $number, $domain = 'default') {
|
||||
global $l10n;
|
||||
return $l10n->ngettext($single, $plural, $number);
|
||||
|
||||
if (isset($l10n[$domain])) {
|
||||
return $l10n[$domain]->ngettext($single, $plural, $number);
|
||||
} else {
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
function load_textdomain($domain, $mofile) {
|
||||
global $l10n;
|
||||
|
||||
if ( is_readable($mofile)) {
|
||||
$input = new FileReader($mofile);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$l10n[$domain] = new gettext_reader($input);
|
||||
}
|
||||
|
||||
function load_plugin_textdomain($domain) {
|
||||
global $locale;
|
||||
|
||||
$mofile = ABSPATH . "wp-content/plugins/$domain-$locale.mo";
|
||||
load_textdomain($domain, $mofile);
|
||||
}
|
||||
|
||||
function load_theme_textdomain($domain) {
|
||||
global $locale;
|
||||
|
||||
$mofile = get_template_directory() . "/$locale.mo"";
|
||||
load_textdomain($domain, $mofile);
|
||||
}
|
||||
|
||||
require($curpath . 'locale.php');
|
||||
|
|
Loading…
Reference in New Issue