Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidjguru/8bdeef7421a4cfde5df311b271d73d88 to your computer and use it in GitHub Desktop.
Save davidjguru/8bdeef7421a4cfde5df311b271d73d88 to your computer and use it in GitHub Desktop.
i18n: Loading a new Language in a Drupal installation
// Sets the target and loads the current languages in your Drupal installation.
$code = 'pt';
$current_langcodes = \Drupal::languageManager()->getLanguages();
$current_langcodesList = array_keys($current_langcodes);
 
// Only creates the referred language if not exists.
if (!in_array($code, $current_langcodesList)){
    $language = ConfigurableLanguage::createFromLangcode($code);
    $language->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment