How to change the list of modules and locale when installing via drush?

I am new to farmOS, but I am trying to deploy farmOS for hundreds of farmers in my country that have been affected by a sudden legal requirement to keep electronic records.

To automate the installation (which will be triggered via a form), I want to install each instance using drush, not in English, and give it a list of modules to install (depending on whether they are in agriculture, cattle, etc.).

I am using the official Docker images.

My specific question is:

  1. Can I change the language to something other than English at installation time? If yes, how? If not, what other approach might work? I’m guessing other languages are not included in the Docker image so I should rebuild it with the languages I want.
  2. The one I can’t figure out: How can I control the list of modules, or create installation profiles to use with Drush?

Thank you!!

2 Likes

Hi @jorgeig ! Sounds like an exciting project :slight_smile:

For languages, I’m not sure if you can technically set a different language right at installation time. It would need to be a flag for drush site-install but you would also need to have the additional languages downloaded.
And you are correct, these are not included in the docker image but are something you could build into your own image. However you may not need to include languages in your docker image if you are using the drupal hosted translations.

In our farmOS demo site I do all of this right after installation… this isn’t fully tested or designed for production but should be a fine approach. There are two steps which I have examples of:

  1. Download & import additional languages
        # Download and import farmOS translations. 
         # TODO: Add --autocreate-language flag for drush 11. 
         for locale in de es it nl 
         do 
           curl "https://ftp.drupal.org/files/translations/all/farm/farm-2.0.0-beta7.$locale.po" -o "/opt/drupal/web/sites/default/files/translations/farm-$locale.po" --silent 
           drush locale:import $locale /opt/drupal/web/sites/default/files/translations/farm-$locale.po 
         done 
  
         # Update all module translations. 
         drush locale:update
  1. Set the default language so new users will start with this language, else they would need to change language when configuring their profile.
drush config:set language.negotiation selected_langcode "$LANGCODE" --yes

Regarding installing a list of modules, this is also something you will need to do after each instance is installed. You are thinking in the right direction with installation profiles but farmOS itself is already a profile so that isn’t an option :slight_smile: Drush should work fine for this, you’ll just need some logic in your installation process that can accompany what was submitted with the form.

3 Likes

Welcome to the forum @jorgeig!

I just wanted to add the link to our official docs for setting up translations, if you haven’t already seen them: Translating farmOS | farmOS

That is the only way that I’ve tested things, so I can’t speak to other approaches. There may be Drush commands that can accomplish many of the same things. If you find a good set of commands that work, please share them so we can learn together!

@paul121 I think your commands are only downloading translations for the farmOS profile, but not for all other core/contrib translations?

One other tip I can share: farmOS provides a shortcut/helper for selecting which farmOS-specific modules get installed during drush site-install, which may be helpful to you. It works as follows:

Install ALL farmOS modules:

drush site-install [args] farm farm.modules='all'

Install DEFAULT farmOS modules:

drush site-install [args] farm farm.modules='default'

Install only BASE farmOS module:

drush site-install [args] farm farm.modules='base'

It is also possible to specify a list of modules (in JSON format) in that argument, but I don’t really recommend that because you need to make sure that you include all the individual base modules in the list otherwise farmOS might not work correctly. And if that list of base modules ever changes in the future it could break your workflow.

So I would probably recommend using the base option to install base farmOS modules and then run additional drush en [module-name] commands after site-install to install the modules you want.

Or, create your own custom module that depends on all the modules you want to install, and just install that one. You might be able to automate some of the language setup in that module’s hook_install() as well. All of this is pretty advanced usage, but possible.

Please share what you learn! :smile:

1 Like

Yeah that is interesting. It must be pulling in other translations though, things like the user profile (drupal core) are translated in the demo. Not sure about contrib modules. Worth noting that URL does use the farmOS beta release… Previously I saw an issue where translation “releases” stopped being generated for our later beta releases. Should check the latest releases to make sure this is working OK.

Thanks a lot both for your responses!

I decided to take the approach of installing base and then installing all the modules for each farm type using drush. I’ll share the end result once I have it running (ideally, all on AWS serverless, but let’s see).

About the languages: like the above, I will do it after installing it. One thing I noticed: when I query the languages with the API via https://localhost/api/configurable_language/configurable_language, all languages have langcode: en set:

{
"type": "configurable_language--configurable_language",
"id": "3e29724b-3714-47c3-a290-1b97a74808ef",
"links": {
"self": {
"href": "https://localhost/api/configurable_language/configurable_language/3e29724b-3714-47c3-a290-1b97a74808ef"
}
},
"attributes": {
"langcode": "en",
"status": true,
"dependencies": [],
"drupal_internal__id": "en",
"label": "Inglés",
"direction": "ltr",
"weight": 0,
"locked": false
}
},
{
"type": "configurable_language--configurable_language",
"id": "c65da110-d316-44f9-b31a-4cc3c8bbfb27",
"links": {
"self": {
"href": "https://localhost/api/configurable_language/configurable_language/c65da110-d316-44f9-b31a-4cc3c8bbfb27"
}
},
"attributes": {
"langcode": "en",
"status": true,
"dependencies": [],
"drupal_internal__id": "es",
"label": "Español",
"direction": "ltr",
"weight": 1,
"locked": false
}
},
{
"type": "configurable_language--configurable_language",
"id": "60f18e1c-89a6-4278-a100-36a8fab60e83",
"links": {
"self": {
"href": "https://localhost/api/configurable_language/configurable_language/60f18e1c-89a6-4278-a100-36a8fab60e83"
}
},
"attributes": {
"langcode": "en",
"status": true,
"dependencies": [],
"drupal_internal__id": "gl",
"label": "Galician",
"direction": "ltr",
"weight": 2,
"locked": false
}
},

Is that expected? You can see it in the DB too, in the users_field_data table.

1 Like

This may have to do with the fact that farmOS enforces en as the default language.

To understand exactly what this means and why, see: https://www.drupal.org/project/farm/issues/3257430

And please note (from the first sentence of that issue):

The title of this issue is a bit misleading, because I am not suggesting we remove the ability to change the default language of a farmOS instance. I am specifically referring to default_langcode in the system.site configuration.

Worth noting…

… you are querying “configuration entities” at that endpoint, so the langcode: en in that context means that the config entity itself has a language of “English”, but each of them are configuring other languages. The drupal_internal__id is the important one to look at when you are parsing those entities via API.

Many thanks for the resources and clarifications!

1 Like