function locale_add_language

7.x locale_add_language($langcode, $name = NULL, $native = NULL, $direction = LANGUAGE_LTR, $domain = '', $prefix = '', $enabled = TRUE, $default = FALSE)

API function to add a language.


$langcode: Language code.

$name: English name of the language

$native: Native name of the language


$domain: Optional custom domain name with protocol, without trailing slash (eg.

$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

11 calls to locale_add_language()
DateTimeFunctionalTest::testDateFormatStorage in drupal/modules/system/system.test
Test if the date formats are stored properly.
DrupalHTTPRequestTestCase::testDrupalHTTPRequestHeaders in drupal/modules/simpletest/tests/common.test
Tests Content-language headers generated by Drupal.
FieldTranslationsTestCase::setUp in drupal/modules/field/tests/field.test
Set the default field storage backend for fields created during tests.
install_import_locales in drupal/includes/
Imports languages via a batch process during installation.
LocaleMultilingualFieldsFunctionalTest::setUp in drupal/modules/locale/locale.test
Sets up a Drupal site for running functional and integration tests.

... See full list


drupal/includes/, line 559
Administration functions for locale.module.


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)) {
    include_once DRUPAL_ROOT . '/includes/';
    $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;

    'language' => $langcode,
    'name' => $name,
    'native' => $native,
    'direction' => $direction,
    'domain' => $domain,
    'prefix' => $prefix,
    'enabled' => $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);

  // Kill the static cache in language_list().

  // Force JavaScript translation file creation for the newly added language.

  watchdog('locale', 'The %language language (%code) has been created.', array('%language' => $name, '%code' => $langcode));