-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way to automate the instalation of drupal in a language other than english #704
Open
mariano-dagostino
wants to merge
3
commits into
main
Choose a base branch
from
688-default-language
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
## Description: Configures drupal to install language | ||
## Usage: setup-language LANGCODE | ||
## Example: "ddev setup-language es Spanish" | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "Usage: $0 <langcode> <language name>" | ||
exit 1 | ||
fi | ||
|
||
langcode=$1 | ||
langname=$2 | ||
|
||
# The site is configured in english. Nothing to do here. | ||
if [ "$langcode" == "en" ]; then | ||
exit 0 | ||
fi | ||
|
||
directories=( | ||
"config/sync" | ||
"web/modules/custom/server_default_content" | ||
) | ||
|
||
# Find and replace "langcode: en" with "langcode: $langcode" | ||
for dir in "${directories[@]}"; do | ||
if [ -d "$dir" ]; then | ||
grep -rl "langcode: en" "$dir" | while read -r file; do | ||
sed -i "s/langcode: en/langcode: $langcode/g" "$file" | ||
done | ||
fi | ||
done | ||
|
||
TARGET_FILE="config/sync/language.entity.${langcode}.yml" | ||
|
||
# Make sure the language selected exists. If not, reuse Spanish as source. | ||
if [ ! -f "$TARGET_FILE" ]; then | ||
mv config/sync/language.entity.es.yml "$TARGET_FILE" | ||
|
||
sed -i "s/id: es/id: ${langcode}/" "$TARGET_FILE" | ||
sed -i "s/label: Spanish/label: ${langname}/" "$TARGET_FILE" | ||
sed -i "s/weight: 2/weight: -1/" "$TARGET_FILE" | ||
|
||
sed -i "s/en: ''/en: en/" config/sync/language.negotiation.yml | ||
sed -i "s/es: es/${langcode}: ${langcode}/" config/sync/language.negotiation.yml | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 agit commit
even.https://gorannikolovski.com/snippet/how-programmatically-add-language#:~:text=Sometimes%20you%20have%20to%20add,)%3B%20%24language%2D%3Esave()%3B
Also
(AI, as-is)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.