Commit 301cbcaf authored by webchick's avatar webchick

Issue #2030537 by janoka, Sutharsan, Gábor Hojtsy | Outi: Fixed Translations...

Issue #2030537 by janoka, Sutharsan, Gábor Hojtsy | Outi: Fixed Translations not downloaded when adding a new language.
parent e8b5a655
......@@ -62,11 +62,14 @@ function locale_translation_build_projects() {
foreach ($projects as $name => $data) {
if (isset($project_updates[$name]['releases']) && $project_updates[$name]['project_status'] != 'not-fetched') {
// Find out if a dev version is installed.
if (preg_match("/^[0-9]+\.x-([0-9]+)\..*-dev$/", $data['info']['version'], $matches)) {
if (preg_match("/^\d+\.x-(\d+)\..*-dev$/", $data['info']['version'], $matches) ||
preg_match("/^(\d+)\.\d+\.\d+.*-dev$/", $data['info']['version'], $matches)) {
// Find a suitable release to use as alternative translation.
foreach ($project_updates[$name]['releases'] as $project_release) {
// The first release with the same major release number which is not a
// dev release is the one. Releases are sorted the most recent first.
// For example the major release number for a contrib module
// 8.x-2.x-dev is "2", for core 8.1.0-dev is "8".
// @todo http://drupal.org/node/1774024 Make a helper function.
if ($project_release['version_major'] == $matches[1] &&
(!isset($project_release['version_extra']) || $project_release['version_extra'] != 'dev')) {
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains Drupal\locale\Tests\LocaleUpdateTest.
* Contains Drupal\locale\Tests\LocaleUpdateBase.
*/
namespace Drupal\locale\Tests;
......@@ -42,13 +42,19 @@ abstract class LocaleUpdateBase extends WebTestBase {
*
* @var array
*/
public static $modules = array('update', 'locale', 'locale_test');
public static $modules = array('update', 'update_test', 'locale', 'locale_test');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Update module should not go out to d.o to check for updates. We override
// the url to the default update_test xml path. But without providing
// a mock xml file, no update data will be found.
\Drupal::config('update.settings')->set('fetch.url', url('update-test', array('absolute' => TRUE)))->save();
// Setup timestamps to identify old and new translation sources.
$this->timestampOld = REQUEST_TIME - 300;
$this->timestampMedium = REQUEST_TIME - 200;
......
<?php
/**
* @file
* Contains \Drupal\locale\src\Tests\LocaleUpdateNotDevelopmentReleaseTest.
*/
namespace Drupal\locale\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Test for finding the first available normal core release version,
* in case of core is a development release.
*
* @group language
*/
class LocaleUpdateNotDevelopmentReleaseTest extends WebTestBase {
public static $modules = array('update', 'locale', 'locale_test_not_development_release');
protected function setUp() {
parent::setUp();
module_load_include('compare.inc', 'locale');
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer languages', 'access administration pages', 'translate interface'));
$this->drupalLogin($admin_user);
$this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'hu'), t('Add language'));
}
public function testLocaleUpdateNotDevelopmentRelease() {
// Set available Drupal releases for test.
$available = array(
'title' => 'Drupal core',
'short_name' => 'drupal',
'type' => 'project_core',
'api_version' => '8.x',
'project_status' => 'unsupported',
'link' => 'https://www.drupal.org/project/drupal',
'terms' => '',
'releases' => array(
'8.0.0-alpha110' => array(
'name' => 'drupal 8.0.0-alpha110',
'version' => '8.0.0-alpha110',
'tag' => '8.0.0-alpha110',
'version_major' => '8',
'version_minor' => '0',
'version_patch' => '0',
'version_extra' => 'alpha110',
'status' => 'published',
'release_link' => 'https://www.drupal.org/node/2316617',
'download_link' => 'http://ftp.drupal.org/files/projects/drupal-8.0.0-alpha110.tar.gz',
'date' => '1407344628',
'mdhash' => '9d71afdd0ce541f2ff5ca2fbbca00df7',
'filesize' => '9172832',
'files' => '',
'terms' => array(),
),
'8.0.0-alpha100' => array(
'name' => 'drupal 8.0.0-alpha100',
'version' => '8.0.0-alpha100',
'tag' => '8.0.0-alpha100',
'version_major' => '8',
'version_minor' => '0',
'version_patch' => '0',
'version_extra' => 'alpha100',
'status' => 'published',
'release_link' => 'https://www.drupal.org/node/2316617',
'download_link' => 'http://ftp.drupal.org/files/projects/drupal-8.0.0-alpha100.tar.gz',
'date' => '1407344628',
'mdhash' => '9d71afdd0ce541f2ff5ca2fbbca00df7',
'filesize' => '9172832',
'files' => '',
'terms' => array(),
),
),
);
$available['last_fetch'] = REQUEST_TIME;
\Drupal::keyValueExpirable('update_available_releases')->setWithExpire('drupal', $available, 10);
$projects = locale_translation_build_projects();
$this->verbose($projects['drupal']->info['version']);
$this->assertEqual($projects['drupal']->info['version'], '8.0.0-alpha110', 'The first release with the same major release number which is not a development release.');
}
}
......@@ -40,6 +40,11 @@ function locale_test_system_info_alter(&$info, Extension $file, $type) {
* test script in order for this hook to take effect.
*/
function locale_test_locale_translation_projects_alter(&$projects) {
// Drupal core should not be translated. By overriding the server pattern we
// make sure that no translation for drupal core will be found and that the
// translation update system will not go out to l.d.o to check.
$projects['drupal']['server_pattern'] = 'translations://';
if (\Drupal::state()->get('locale.test_projects_alter')) {
// Instead of the default ftp.drupal.org we use the file system of the test
......
name: 'Locale Test Not Development Release'
type: module
description: 'The first release with the same major release number which is not a development release.'
package: Testing
version: VERSION
core: 8.x
hidden: true
<?php
/**
* @file
* Simulate a Drupal version.
*/
use Drupal\Core\Extension\Extension;
/**
* Implements hook_system_info_alter().
*
* Change the core version number to a development one for testing.
* 8.0.0-alpha102-dev is the simulated version.
*/
function locale_test_not_development_release_system_info_alter(&$info, Extension $file, $type) {
if (isset($info['package']) && $info['package'] == 'Core') {
$info['version'] = '8.0.0-alpha102-dev';
}
}
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