/**
 * Adds a language with the default locale, name and direction.
 *
 * @param string $language_code ISO 639 or locale code
 * @param int $language_order language order [optional]
 * @param int &$error_code the error code, or 0 if the operation is successful
 * @return bool true if the language has been added; false if an error has occured
 */
function pll_add_language($language_code, $language_order = 0, &$error_code = 0)
{
    global $polylang;
    $adminModel = new PLL_Admin_Model($polylang->options);
    $info = pll_get_default_language_information($language_code);
    $args = array(name => $info['name'], slug => $info['code'], locale => $info['locale'], rtl => $info['rtl'] ? 1 : 0, term_group => $language_order);
    $error_code = $adminModel->add_language($args);
    return $error_code !== 0;
}
Example #2
0
 protected static function create_first_language()
 {
     global $polylang;
     include PLL_ADMIN_INC . '/languages.php';
     $locale = get_locale();
     // attempts to set the default language from the current locale
     foreach ($languages as $lang) {
         if (get_locale() == $lang[1]) {
             $language = $lang;
         }
     }
     // defaults to en_US
     if (empty($language)) {
         $language = array('en', 'en_US', 'English');
     }
     $pll_model = new PLL_Admin_Model($polylang->options);
     // need admin model
     $pll_model->add_language(array('slug' => $language[0], 'locale' => $language[1], 'name' => $language[2], 'rtl' => isset($language[3]) ? 1 : 0, 'term_group' => 0));
 }