You are here

function locale_add_language in Drupal 6

Same name and namespace in other branches
  1. 7 includes/locale.inc \locale_add_language()

API function to add a language.

Parameters

$langcode: Language code.

$name: English name of the language

$native: Native name of the language

$direction: LANGUAGE_LTR or LANGUAGE_RTL

$domain: Optional custom domain name with protocol, without trailing slash (eg. http://de.example.com).

$prefix: Optional path prefix for the language. Defaults to the language code if omitted.

$enabled: Optionally TRUE to enable the language when created or FALSE to disable.

$default: Optionally set this language to be the default.

Related topics

3 calls to locale_add_language()
install_tasks in ./install.php
Tasks performed after the database is initialized.
locale_languages_predefined_form_submit in includes/locale.inc
Process the language addition form submission.
locale_translate_import_form_submit in includes/locale.inc
Process the locale import form submission.

File

includes/locale.inc, line 986
Administration functions for locale.module.

Code

function locale_add_language($langcode, $name = NULL, $native = NULL, $direction = LANGUAGE_LTR, $domain = '', $prefix = '', $enabled = TRUE, $default = FALSE) {

  // Default prefix on language code.
  if (empty($prefix)) {
    $prefix = $langcode;
  }

  // If name was not set, we add a predefined language.
  if (!isset($name)) {
    $predefined = _locale_get_predefined_list();
    $name = $predefined[$langcode][0];
    $native = isset($predefined[$langcode][1]) ? $predefined[$langcode][1] : $predefined[$langcode][0];
    $direction = isset($predefined[$langcode][2]) ? $predefined[$langcode][2] : LANGUAGE_LTR;
  }
  db_query("INSERT INTO {languages} (language, name, native, direction, domain, prefix, enabled) VALUES ('%s', '%s', '%s', %d, '%s', '%s', %d)", $langcode, $name, $native, $direction, $domain, $prefix, $enabled);

  // Only set it as default if enabled.
  if ($enabled && $default) {
    variable_set('language_default', (object) array(
      'language' => $langcode,
      'name' => $name,
      'native' => $native,
      'direction' => $direction,
      'enabled' => (int) $enabled,
      'plurals' => 0,
      'formula' => '',
      'domain' => '',
      'prefix' => $prefix,
      'weight' => 0,
      'javascript' => '',
    ));
  }
  if ($enabled) {

    // Increment enabled language count if we are adding an enabled language.
    variable_set('language_count', variable_get('language_count', 1) + 1);
  }

  // Force JavaScript translation file creation for the newly added language.
  _locale_invalidate_js($langcode);
  watchdog('locale', 'The %language language (%code) has been created.', array(
    '%language' => $name,
    '%code' => $langcode,
  ));
}