Plugin and theme localization.

git-svn-id: https://develop.svn.wordpress.org/trunk@1808 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2004-10-18 02:27:35 +00:00
parent 38f8395c4a
commit e41ead7068
1 changed files with 51 additions and 10 deletions

View File

@ -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) {
global $l10n;
return $l10n->translate($text);
function __($text, $domain = 'default') {
global $l10n;
if (isset($l10n[$domain])) {
return $l10n[$domain]->translate($text);
} else {
return $text;
}
}
// Echo a translated string.
function _e($text) {
global $l10n;
echo $l10n->translate($text);
function _e($text, $domain = 'default') {
global $l10n;
if (isset($l10n[$domain])) {
echo $l10n[$domain]->translate($text);
} else {
echo $text;
}
}
// Return the plural form.
function __ngettext($single, $plural, $number) {
global $l10n;
return $l10n->ngettext($single, $plural, $number);
function __ngettext($single, $plural, $number, $domain = 'default') {
global $l10n;
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');