Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/24/2008 10:53:25 AM (18 years ago)
Author:
sambauers
Message:

Multi language support for installer.

Installer will now detect the existence of language files in BB_LANG_DIR and return the option on step zero to select a language to use during installation.

A language can also be selected for the installation independently from the installer language. So a person can install a foreign forum in their chosen language. A true "border" case. Boom-tish.

Also contained in this commit is the long awaited RTL installation CSS.

Fixes #839

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-admin/class-install.php

    r1353 r1370  
    2020     **/
    2121    var $load_includes = false;
     22   
     23    /**
     24     * An array of available languages to use in the installer
     25     *
     26     * @var array
     27     **/
     28    var $languages = array('en_US' => 'en_US');
     29   
     30    /**
     31     * The currently selected language for the installer
     32     *
     33     * @var string
     34     **/
     35    var $language = 'en_US';
    2236   
    2337    /**
     
    129143                'intro'       => array(
    130144                    __('We\'re now going to go through a few steps to get you up and running.'),
     145                    $this->get_language_selector(),
    131146                    sprintf(__('Ready? Then <a href="%s">let\'s get started!</a>'), 'install.php?step=1')
    132147                )
     
    185200    function check_prerequisites()
    186201    {
    187         if (phpversion() < '4.2') {
    188             $this->strings[-1]['messages']['error'][] = sprintf(__('Your server is running PHP version %s but bbPress requires at least 4.2'), phpversion());
     202        if (version_compare(PHP_VERSION, '4.3', '<')) {
     203            $this->strings[-1]['messages']['error'][] = sprintf(__('Your server is running PHP version %s but bbPress requires at least 4.3'), PHP_VERSION);
    189204            $this->step = -1;
    190205        }
     
    201216        }
    202217       
     218        if (defined('DB_NAME') || defined('WP_BB') && WP_BB) {
     219            $this->strings[-1]['messages']['error'][] = __('Please complete your installation before attempting to include WordPress within bbPress');
     220            $this->step = -1;
     221        }
     222       
    203223        if ($this->step === -1) {
    204224            return false;
     
    248268        }
    249269       
     270        // Define the language file directory
     271        if ( !defined('BB_LANG_DIR') )
     272            define('BB_LANG_DIR', BB_PATH . BB_INC . 'languages/'); // absolute path with trailing slash
     273       
    250274        return true;
     275    }
     276   
     277    /**
     278     * Gets an array of available languages form the language directory
     279     *
     280     * @return array
     281     **/
     282    function get_languages()
     283    {
     284        foreach (bb_glob(BB_LANG_DIR . '*.mo') as $language) {
     285            $language = str_replace('.mo', '', basename($language));
     286            $this->languages[$language] = $language;
     287        }
     288        return $this->languages;
     289    }
     290   
     291    /**
     292     * Returns a language selector for switching installation languages
     293     *
     294     * @return string|false Either the html for the selector or false if there are no languages
     295     **/
     296    function get_language_selector()
     297    {
     298        // Don't provide a selection if there is only english
     299        if (count($this->languages) < 2) {
     300            return false;
     301        }
     302       
     303        $r = '<script type="text/javascript" charset="utf-8">' . "\n";
     304        $r .= ' function changeLanguage(selectObj) {' . "\n";
     305        $r .= '     var selectedLanguage = selectObj.options[selectObj.selectedIndex].value;' . "\n";
     306        $r .= '     location.href = "install.php?language=" + selectedLanguage;' . "\n";
     307        $r .= ' }' . "\n";
     308        $r .= '</script>' . "\n";
     309        $r .= '<form id="lang" action="install.php?step=' . $this->step . '">' . "\n";
     310        $r .= ' <label>' . "\n";
     311        $r .= '     ' . __('Please select the language you wish to use during installation -') . "\n";
     312        $r .= '     <select onchange="changeLanguage(this);" name="language">' . "\n";
     313        foreach ($this->languages as $language) {
     314            $selected = '';
     315            if ($language == $this->language) {
     316                $selected = ' selected="selected"';
     317            }
     318            $r .= '         <option value="' . $language . '"' . $selected . '>' . $language . '</option>' . "\n";
     319        }
     320        $r .= '     </select>' . "\n";
     321        $r .= ' </label>' . "\n";
     322        $r .= '</form>' . "\n";
     323       
     324        return $r;
     325    }
     326   
     327    /**
     328     * Sets the current installation language
     329     *
     330     * @return string The currently set language
     331     **/
     332    function set_language()
     333    {
     334        if (isset($_COOKIE['bb_install_language']) && count($this->languages) > 1) {
     335            if (in_array($_COOKIE['bb_install_language'], $this->languages)) {
     336                $this->language = $_COOKIE['bb_install_language'];
     337            }
     338        }
     339       
     340        if ($_GET['language'] && count($this->languages) > 1) {
     341            if (in_array($_GET['language'], $this->languages)) {
     342                $this->language = $_GET['language'];
     343                setcookie('bb_install_language', $this->language);
     344            }
     345        }
     346       
     347        if (!$this->language || $this->language == 'en_US') {
     348            $this->language = 'en_US';
     349            setcookie('bb_install_language', ' ', time() - 31536000);
     350        }
     351       
     352        return $this->language;
    251353    }
    252354   
     
    448550                        'note'  => __('That database user\'s password.')
    449551                    ),
     552                    'bb_lang' => array(
     553                        'value' => '',
     554                        'label' => __('Language'),
     555                        'note' => sprintf(__('The language which bbPress will be presented in once installed. Your current language choice (%s) will remain for the rest of the install process.'), $this->language)
     556                    ),
    450557                    'toggle_1' => array(
    451558                        'value'   => 0,
     
    832939       
    833940        $data =& $this->data[1]['form'];
     941       
     942        if ($data['bb_lang']['value'] == 'en_US') {
     943            $data['bb_lang']['value'] = '';
     944        }
    834945       
    835946        $data['bb_table_prefix']['value'] = preg_replace('/[^0-9a-zA-Z_]/', '', $data['bb_table_prefix']['value']);
     
    9091020                    $config_lines[] = str_replace("'bb_'", "'" . $data['bb_table_prefix']['value'] . "'", $line);
    9101021                    break;
     1022                case "define('BB_LANG', ":
     1023                    $config_lines[] = str_replace("''", "'" . $data['bb_lang']['value'] . "'", $line);
     1024                    break;
    9111025                default:
    9121026                    $config_lines[] = $line;
     
    13031417        // Check the referer
    13041418        bb_check_admin_referer('bbpress-installer');
    1305         $installation_log[] = __('Referrer is OK, beginning installation...');
     1419        $installation_log[] = __('Referrer is OK, beginning installation&hellip;');
    13061420       
    13071421        global $bbdb;
     
    16031717            if ($forum_id = bb_new_forum(array('forum_name' => $data3['forum_name']['value']))) {
    16041718                $installation_log[] = '>>> ' . __('Forum name:') . ' ' . $data3['forum_name']['value'];
     1719               
     1720                if ($this->language != BB_LANG) {
     1721                    global $locale, $l10n;
     1722                    $locale = BB_LANG;
     1723                    unset($l10n['default']);
     1724                    load_default_textdomain();
     1725                }
     1726               
     1727                $topic_title = __('Your first topic');
    16051728                $topic_id = bb_insert_topic(
    16061729                    array(
    1607                         'topic_title' => __('Your first topic'),
     1730                        'topic_title' => $topic_title,
    16081731                        'forum_id' => $forum_id,
    16091732                        'tags' => 'bbPress'
    16101733                    )
    16111734                );
    1612                 $installation_log[] = '>>>>>> ' . __('Topic:') . ' ' . __('Your first topic');
     1735                $post_text = __('First Post!  w00t.');
    16131736                bb_insert_post(
    16141737                    array(
    16151738                        'topic_id' => $topic_id,
    1616                         'post_text' => __('First Post!  w00t.')
     1739                        'post_text' => $post_text
    16171740                    )
    16181741                );
    1619                 $installation_log[] = '>>>>>>>>> ' . __('Post:') . ' ' . __('First Post!  w00t.');
     1742               
     1743                if ($this->language != BB_LANG) {
     1744                    $locale = $this->language;
     1745                    unset($l10n['default']);
     1746                    load_default_textdomain();
     1747                }
     1748               
     1749                $installation_log[] = '>>>>>> ' . __('Topic:') . ' ' . $topic_title;
     1750                $installation_log[] = '>>>>>>>>> ' . __('Post:') . ' ' . $post_text;
    16201751            } else {
    16211752                $installation_log[] = '>>> ' . __('Forum could not be created!');
     
    16611792    }
    16621793   
    1663     function input_text($key)
     1794    function input_text($key, $direction = false)
    16641795    {
    16651796        $data = $this->data[$this->step]['form'][$key];
     
    16931824        }
    16941825       
    1695         $r .= '<input type="' . $type . '" id="' . $key . '" name="' . $key . '" class="text" value="' . $data['value'] . '"' . $maxlength . ' />' . "\n";
     1826        if ($direction) {
     1827            $direction = ' dir="' . $direction . '"';
     1828        }
     1829       
     1830        $r .= '<input' . $direction . ' type="' . $type . '" id="' . $key . '" name="' . $key . '" class="text" value="' . $data['value'] . '"' . $maxlength . ' />' . "\n";
    16961831        $r .= '</label>' . "\n";
    16971832       
     
    17101845    }
    17111846   
    1712     function textarea($key)
     1847    function textarea($key, $direction = false)
    17131848    {
    17141849        $data = $this->data[$this->step]['form'][$key];
     
    17201855        }
    17211856       
    1722         $r .= '<textarea id="' . $key . '" rows="5" cols="30">' . $data['value'] . '</textarea>' . "\n";
     1857        if ($direction) {
     1858            $direction = ' dir="' . $direction . '"';
     1859        }
     1860       
     1861        $r .= '<textarea' . $direction . ' id="' . $key . '" rows="5" cols="30">' . $data['value'] . '</textarea>' . "\n";
    17231862        $r .= '</label>' . "\n";
    17241863       
     
    17691908       
    17701909        echo $r;
     1910    }
     1911   
     1912    function select_language()
     1913    {
     1914        if (count($this->languages) > 1) {
     1915            $this->data[1]['form']['bb_lang']['value'] = $this->language;
     1916            $this->data[1]['form']['bb_lang']['options'] = $this->languages;
     1917            $this->select('bb_lang');
     1918        } else {
     1919            $this->data[1]['form']['bb_lang']['value'] = 'en_US';
     1920            $this->input_hidden('bb_lang');
     1921        }
    17711922    }
    17721923   
Note: See TracChangeset for help on using the changeset viewer.