Commit 4d769bcc authored by plach's avatar plach

Issue #2955869 by alexpott, dawehner, plach: Fix multilingual install on...

Issue #2955869 by alexpott, dawehner, plach: Fix multilingual install on Drupal dev version for CLI utilities
parent c0c17636
......@@ -1432,7 +1432,7 @@ function install_check_localization_server($uri) {
*
* @param string $version
* Version info string (e.g., 8.0.0, 8.1.0, 8.0.0-dev, 8.0.0-unstable1,
* 8.0.0-alpha2, 8.0.0-beta3, and 8.0.0-rc4).
* 8.0.0-alpha2, 8.0.0-beta3, 8.6.x, and 8.0.0-rc4).
*
* @return array
* Associative array of version info:
......@@ -1450,7 +1450,7 @@ function _install_get_version_info($version) {
\. # .
(?P<minor>[0-9]+) # Minor release number.
\. # .
(?P<patch>[0-9]+) # Patch release number.
(?P<patch>[0-9]+|x) # Patch release number.
) #
( #
- # - separator for "extra" version information.
......@@ -1722,6 +1722,9 @@ function _install_prepare_import($langcodes, $server_pattern) {
];
\Drupal::service('locale.project')->set($data['name'], $data);
module_load_include('compare.inc', 'locale');
// Reset project information static cache so that it uses the data
// set above.
locale_translation_clear_cache_projects();
locale_translation_check_projects_local(['drupal'], [$langcode]);
}
}
......@@ -1857,10 +1860,19 @@ function install_check_translations($langcode, $server_pattern) {
return;
}
$version = \Drupal::VERSION;
// For dev releases, remove the '-dev' part and trust the translation server
// to fall back to the latest stable release for that branch.
// @see locale_translation_build_projects()
if (preg_match("/^(\d+\.\d+\.).*-dev$/", $version, $matches)) {
// Example match: 8.0.0-dev => 8.0.x (Drupal core)
$version = $matches[1] . 'x';
}
// Build URL for the translation file and the translation server.
$variables = [
'%project' => 'drupal',
'%version' => \Drupal::VERSION,
'%version' => $version,
'%core' => \Drupal::CORE_COMPATIBILITY,
'%language' => $langcode,
];
......
<?php
namespace Drupal\Tests\locale\Functional;
/**
* Tests installing in a different language with a dev version string.
*
* @group locale
*/
class LocaleNonInteractiveDevInstallTest extends LocaleNonInteractiveInstallTest {
/**
* {@inheritdoc}
*/
protected function getVersionStringToTest() {
include_once $this->root . '/core/includes/install.core.inc';
$version = _install_get_version_info(\Drupal::VERSION);
return $version['major'] . '.' . $version['minor'] . '.x';
}
}
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests installing in a different language with a non-dev version string.
*
* @group locale
*/
class LocaleNonInteractiveInstallTest extends BrowserTestBase {
/**
* Gets the version string to use in the translation file.
*
* @return string
* The version string to test, for example, '8.0.0' or '8.6.x'.
*/
protected function getVersionStringToTest() {
include_once $this->root . '/core/includes/install.core.inc';
$version = _install_get_version_info(\Drupal::VERSION);
return $version['major'] . '.0.0';
}
/**
* {@inheritdoc}
*/
protected function installParameters() {
$parameters = parent::installParameters();
// Install Drupal in German.
$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 = <<<ENDPO
msgid ""
msgstr ""
msgid "Enter the password that accompanies your username."
msgstr "Geben sie das Passwort für ihren Benutzernamen ein."
ENDPO;
$version = $this->getVersionStringToTest();
file_put_contents($this->publicFilesDirectory . "/translations/drupal-{$version}.de.po", $contents);
return $parameters;
}
/**
* Tests that the expected translated text appears on the login screen.
*/
public function testInstallerTranslations() {
$this->drupalGet('user/login');
$this->assertSession()->responseContains('Geben sie das Passwort für ihren Benutzernamen ein.');
}
}
......@@ -83,6 +83,11 @@ protected function setUp() {
protected function installParameters() {
$parameters = parent::installParameters();
$parameters['parameters']['langcode'] = $this->defaultLangcode;
// Create an empty po file so we don't attempt to download one from
// localize.drupal.org. It does not need to match the version exactly as the
// multi-lingual system will fallback.
\Drupal::service('file_system')->mkdir($this->publicFilesDirectory . '/translations', NULL, TRUE);
file_put_contents($this->publicFilesDirectory . "/translations/drupal-8.0.0.{$this->defaultLangcode}.po", '');
return $parameters;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment