Plugin and theme localization.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1808 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-10-18 02:27:35 +00:00
parent 4581b28d54
commit b29cb9cb81

View File

@ -29,24 +29,65 @@ if ( is_readable($mofile) && ($locale != 'en_US') ) {
$input = false; $input = false;
} }
$l10n = new gettext_reader($input); $l10n['default'] = new gettext_reader($input);
// Return a translated string. // Return a translated string.
function __($text) { function __($text, $domain = 'default') {
global $l10n; global $l10n;
return $l10n->translate($text);
if (isset($l10n[$domain])) {
return $l10n[$domain]->translate($text);
} else {
return $text;
}
} }
// Echo a translated string. // Echo a translated string.
function _e($text) { function _e($text, $domain = 'default') {
global $l10n; global $l10n;
echo $l10n->translate($text);
if (isset($l10n[$domain])) {
echo $l10n[$domain]->translate($text);
} else {
echo $text;
}
} }
// Return the plural form. // Return the plural form.
function __ngettext($single, $plural, $number) { function __ngettext($single, $plural, $number, $domain = 'default') {
global $l10n; 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'); require($curpath . 'locale.php');