1

I want to set create a language in PHP code (for example, using a hook_update_n implementation) so I can deploy and automate it.

How?

1

Note that Features module supports exporting languages.

Answering the question:

// Example language: fr.
$language = (object)array(
  'language' => 'fr',
  'name' => 'French',
  'native' => 'Français',
  'direction' => 0,
  'enabled' => 1,
  'plurals' => 0,
  'formula' => '',
  'domain' => '',
  'prefix' => 'fr',
  'weight' => 0,
);

locale_add_language($language->language,
  $language->name,
  $language->native,
  $language->direction,
  $language->domain,
  $language->prefix,
  $language->enabled);

// Additional params not implemented in locale_add_language().
db_update('languages')
  ->fields(array(
    'plurals' => $language->plurals,
    'formula' => $language->formula,
  ))
  ->condition('language', $language->language)
  ->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.