Make WordPress Core

Changeset 1808


Ignore:
Timestamp:
10/18/2004 02:27:35 AM (20 years ago)
Author:
rboren
Message:

Plugin and theme localization.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/wp-l10n.php

    r1331 r1808  
    3030}
    3131
    32 $l10n = new gettext_reader($input);
     32$l10n['default'] = new gettext_reader($input);
    3333
    3434// Return a translated string.   
    35 function __($text) {
    36     global $l10n;
    37     return $l10n->translate($text);
     35function __($text, $domain = 'default') {
     36    global $l10n;
     37
     38    if (isset($l10n[$domain])) {
     39        return $l10n[$domain]->translate($text);
     40    } else {
     41        return $text;
     42    }
    3843}
    3944
    4045// Echo a translated string.
    41 function _e($text) {
    42     global $l10n;
    43     echo $l10n->translate($text);
     46function _e($text, $domain = 'default') {
     47    global $l10n;
     48
     49    if (isset($l10n[$domain])) {
     50        echo $l10n[$domain]->translate($text);
     51    } else {
     52        echo $text;
     53    }
    4454}
    4555
    4656// Return the plural form.
    47 function __ngettext($single, $plural, $number) {
    48     global $l10n;
    49     return $l10n->ngettext($single, $plural, $number);
     57function __ngettext($single, $plural, $number, $domain = 'default') {
     58    global $l10n;
     59
     60    if (isset($l10n[$domain])) {
     61        return $l10n[$domain]->ngettext($single, $plural, $number);
     62    } else {
     63        return $text;
     64    }
     65}
     66
     67function load_textdomain($domain, $mofile) {
     68    global $l10n;
     69
     70    if ( is_readable($mofile)) {
     71    $input = new FileReader($mofile);
     72    }   else {
     73        return;
     74    }
     75
     76    $l10n[$domain] = new gettext_reader($input);
     77}
     78
     79function load_plugin_textdomain($domain) {
     80    global $locale;
     81   
     82    $mofile = ABSPATH . "wp-content/plugins/$domain-$locale.mo";
     83    load_textdomain($domain, $mofile);
     84}
     85
     86function load_theme_textdomain($domain) {
     87    global $locale;
     88   
     89    $mofile = get_template_directory() . "/$locale.mo"";
     90    load_textdomain($domain, $mofile);
    5091}
    5192
Note: See TracChangeset for help on using the changeset viewer.