Problem/Motivation

In order to install Drupal in a test system in a different language you need to do:

  /**
   * {@inheritdoc}
   */
  protected function installParameters(): array {
    $parameters = parent::installParameters();
    $parameters['parameters']['langcode'] = 'de';
    // Create a po file so we don't attempt to download one from
    // localize.drupal.org and to have a test translation that will not change.
    \Drupal::service('file_system')->mkdir($this->publicFilesDirectory . '/translations', NULL, TRUE);
    $contents = <<<PO
msgid ""
msgstr ""

PO;
    file_put_contents($this->publicFilesDirectory . '/translations/drupal-' . \Drupal::VERSION . '.de.po', $contents);
    return $parameters;
  }

Proposed resolution

Let's make this simple by introducing a trait that tests can use to install Drupal in different language and it should also make it easy to add translations.

Remaining tasks

User interface changes

None

Introduced terminology

N/a

API changes

New test trait

Data model changes

None

Release notes snippet

N/a

Issue fork drupal-3613629

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
kentr’s picture

to install Drupal in different language

Can you do some of this in a way that's usable outside of automated tests, to help with manual testing / review of issues related to translation? For example, with a recipe?

alexpott’s picture

@kentr is the first thing you answer in the interactive installer and is an option on both dr install and drush site-install ... not sure there's much more we could do for that. Changing the default language of a site is currently fraught so install and then changing that is not going to be solved in a single issue.

kentr’s picture

@alexpott

I just meant installing from scratch with translation fully set up and a different language loaded, not changing the default language of an existing site.

For me, the interactive installer on 12.x-dev (i.e., when working on core issues) doesn't work because the translation files don't exist:

The French translation is not available.
The French translation file is not available at the translation server. Choose a different language or select English and translate your website later.

I've had to manually download and import 11.x versions of translation files.

drush site-install --locale=es also doesn't install a translation file:

Translation file not found: https://ftp.drupal.org/files/translations/all/drupal/drupal-12.0-dev.es.po

dr install won't overwrite an existing site, AFAICT. So reinstalling with a different branch on a dev environment is tedious.

Can something like a recipe can overcome this?

It would be more helpful if it just adds a language anyway, so that one can toggle. That would probably also help with automated testing of issues like #2921627: Do not use a CSS-only required marker in forms per WCAG 2.0.

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

I really like this simplification. The fail seems to be entirely unrelated though. I sent that bit for a retest.

  • amateescu committed f2d23228 on main
    task: #3613629 It should be easier to test Drupal in a different...
amateescu’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed f2d2322 and pushed to main. Thanks!

Needs a rebase on 11.x.

  • amateescu committed ca32739c on 11.x
    task: #3613629 It should be easier to test Drupal in a different...
amateescu’s picture

Status: Patch (to be ported) » Fixed

I backported it myself. The only difference is that the changes to LocaleNonInteractiveInstallTest were dropped, because that test was changed in #3359322: Fix various tests that fail every time we open a new major branch in main and not backported to 11.x.

Committed ca32739 and pushed to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.