Skip to content

Conversation

@mariano-dagostino
Copy link
Collaborator

@@ -0,0 +1,46 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it a bit fragile to do it with string manipulations.
Why not doing this inside Robo?
Then, as Drupal is bootstrapped, we can simply use the API to achieve this. Then we can a drush cex and a git commit even.

https://gorannikolovski.com/snippet/how-programmatically-add-language#:~:text=Sometimes%20you%20have%20to%20add,)%3B%20%24language%2D%3Esave()%3B

Also

<?php

// Ensure this file is executed in the context of a Drupal bootstrap.
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;

if (!drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL)) {
    drush_log('This script must be run in the context of a fully bootstrapped Drupal site.', 'error');
    exit(1);
}

// Define the language code of the new language to be installed.
$new_language_code = 'es'; // Spanish (change 'es' to the desired language code).

// Check if the language already exists.
$existing_language = \Drupal::languageManager()->getLanguage($new_language_code);

if ($existing_language) {
    drush_log(dt('The language @lang_code already exists.', ['@lang_code' => $new_language_code]), 'warning');
    return;
}

// Create and save the new language.
ConfigurableLanguage::create([
    'id' => $new_language_code,
    'label' => 'Spanish', // Change this to the appropriate language name.
    'weight' => 0,
    'locked' => LanguageInterface::LOCKED
])->save();

drush_log(dt('The language @lang_code has been added.', ['@lang_code' => $new_language_code]), 'success');

// Rebuild the cache.
drupal_flush_all_caches();

drush_log('Cache has been cleared.', 'success');

(AI, as-is)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it a bit fragile to do it with string manipulations.

Yep true. Maybe we can set this feature as experimental and use with caution, by default for English it does nothing as it exits before doing any string manipulation.

@AronNovak The reason for leaving this out of Robo is because this approach install all the content in the language of choice. Adding a new language and doing a config export will leave a lot of content created English.

@amitaibu
Copy link
Member

amitaibu commented Sep 6, 2024

Thanks.

I think we should hold this PR, until we get enough real use cases for this (as currently we don't have any in Gizra AFAIK). I think for now whoever tries it could go with the manual work described in #688 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants