Commit 857ded8c authored by webchick's avatar webchick
Browse files

Issue #1627006 follow-up by YesCT, webflo, Gábor Hojtsy: CMI conversion and...

Issue #1627006 follow-up by YesCT, webflo, Gábor Hojtsy: CMI conversion and minor followups to 'Collect project information for translation update'.
parent 83a91f42
translation:
check_disabled_modules: false
default_server_pattern: 'http://ftp.drupal.org/files/translations/%core/%project/%project-%version.%language.po'
......@@ -54,21 +54,24 @@ function testLocaleCompare() {
$this->assertEqual($projects['locale_test']['info']['interface translation server pattern'], 'core/modules/locale/test/modules/locale_test/%project-%version.%language.po', 'Interface translation parameter found in project info.');
$this->assertEqual($projects['locale_test']['name'] , 'locale_test', format_string('%key found in project info.', array('%key' => 'interface translation project')));
// Get the locale settings.
$config = config('locale.settings');
// Check if disabled modules are detected.
variable_set('locale_translation_check_disabled', TRUE);
$config->set('translation.check_disabled_modules', TRUE)->save();
drupal_static_reset('locale_translation_project_list');
$projects = locale_translation_project_list();
$this->assertTrue(isset($projects['locale_test_disabled']), 'Disabled module found');
// Check the fully processed list of project data of both enabled and
// disabled modules.
variable_set('locale_translation_check_disabled', TRUE);
$config->set('translation.check_disabled_modules', TRUE)->save();
drupal_static_reset('locale_translation_project_list');
$projects = locale_translation_get_projects();
$this->assertEqual($projects['drupal']->name, 'drupal', 'Core project found');
$this->assertEqual($projects['locale_test']->server_pattern, 'core/modules/locale/test/modules/locale_test/%project-%version.%language.po', 'Interface translation parameter found in project info.');
$this->assertEqual($projects['locale_test_disabled']->status, '0', 'Disabled module found');
variable_del('locale_translation_check_disabled');
$config->delete('translation.check_disabled_modules');
// Return the locale test modules back to their hidden state.
variable_del('locale_translation_test_system_info_alter');
......
......@@ -11,15 +11,15 @@
*
* .info file properties for interface translation settings.
*
* Modules hosted on drupal.org, a project definition is automatically added to
* the .info file. Only modules with this project definition are discovered by
* the update module and use it to check for new releases. Locale module uses
* the same data to build a list of module to check for new translations.
* For modules hosted on drupal.org, a project definition is automatically added
* to the .info file. Only modules with this project definition are discovered
* by the update module and use it to check for new releases. Locale module uses
* the same data to build a list of modules to check for new translations.
* Therefore modules not hosted at drupal.org, such as custom modules, custom
* themes, features and distributions, need a way to identify themselves to
* the Locale module if they have translations that require to be updated.
*
* Custom module which contain new strings should provide po file(s) containing
* Custom modules which contain new strings should provide po file(s) containing
* source strings and string translations in gettext format. The translation
* file can be located both local and remote. Use the following .info file
* properties to inform Locale module to load and import the translations.
......@@ -78,11 +78,13 @@
* Alter the list of projects to be updated by locale's interface translation.
*
* Locale module attempts to update the translation of those modules returned
* by update_get_projects(). Using this hook the data returned by
* by update_get_projects(). Using this hook, the data returned by
* update_get_projects() can be altered or extended.
*
* Modules or distributions that use a dedicated translation server should use
* this hook to specify the interface translation server pattern.
* this hook to specify the interface translation server pattern, or to add
* additional custom/non-Drupal.org modules to the list of modules known to
* locale.
* - "interface translation server pattern": URL of the .po translation files
* used to download the files from. The URL contains tokens which will be
* replaced by appropriate values.
......
......@@ -37,14 +37,15 @@ function locale_translation_get_projects() {
if (empty($projects)) {
// Get project data from the database.
$projects = array();
$result = db_query('SELECT * FROM {locale_project}');
$result = db_query('SELECT name, project_type, core, version, server_pattern, status FROM {locale_project}');
// http://drupal.org/node/1777106 is a follow-up issue to make the check for
// possible out-of-date project information more robust.
if ($result->rowCount() == 0 && module_exists('update')) {
// At least the core project should be in the database, so we build the
// data if none are found.
locale_translation_build_projects();
$result = db_query('SELECT * FROM {locale_project}');
$result = db_query('SELECT name, project_type, core, version, server_pattern, status FROM {locale_project}');
}
foreach ($result as $project) {
......@@ -77,6 +78,8 @@ function locale_translation_flush_projects() {
* - "project_type": Project type, e.g. 'module', 'theme'.
* - "core": Core release version, e.g. 8.x
* - "version": Project release version, e.g. 8.x-1.0
* See http://drupalcode.org/project/drupalorg.git/blob/refs/heads/7.x-3.x:/drupalorg_project/plugins/release_packager/DrupalorgProjectPackageRelease.class.php#l219
* for how the version strings are created.
* - "server_pattern": Translation server po file pattern.
* - "status": Project status, 1 = enabled.
*/
......@@ -98,6 +101,7 @@ function locale_translation_build_projects() {
$default_server = locale_translation_default_translation_server();
// If project is a dev release, or core, find the latest available release.
$project_updates = update_get_available(TRUE);
foreach ($projects as $name => $data) {
if (isset($project_updates[$name]['releases']) && $project_updates[$name]['project_status'] != 'not-fetched') {
......@@ -107,6 +111,7 @@ function locale_translation_build_projects() {
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.
// @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')) {
$release = $project_release;
......@@ -114,7 +119,8 @@ function locale_translation_build_projects() {
}
}
}
elseif ($name == "drupal" || preg_match("/HEAD/", $data['info']['version'], $matches)) {
// If project is not a dev version, but is core, pick latest release.
elseif ($name == "drupal") {
// Pick latest available release.
$release = array_shift($project_updates[$name]['releases']);
}
......@@ -126,13 +132,14 @@ function locale_translation_build_projects() {
unset($release);
}
// For every project store information.
$data += array(
'version' => isset($data['info']['version']) ? $data['info']['version'] : '',
'core' => isset($data['info']['core']) ? $data['info']['core'] : DRUPAL_CORE_COMPATIBILITY,
// A project can provide the path and filename pattern to download the
// gettext file. Use the default if not.
'server_pattern' => isset($data['info']['interface translation server pattern']) ? $data['info']['interface translation server pattern'] : $default_server['pattern'],
'status' => $data['project_status'] ? 1 : 0,
'status' => !empty($data['project_status']) ? 1 : 0,
);
$project = (object) $data;
$projects[$name] = $project;
......@@ -168,6 +175,7 @@ function locale_translation_project_list() {
$projects = &drupal_static(__FUNCTION__, array());
if (empty($projects)) {
module_load_include('compare.inc', 'update');
$config = config('locale.settings');
$projects = array();
$additional_whitelist = array(
......@@ -178,7 +186,7 @@ function locale_translation_project_list() {
$theme_data = _locale_translation_prepare_project_list(system_rebuild_theme_data(), 'theme');
update_process_info_list($projects, $module_data, 'module', TRUE, $additional_whitelist);
update_process_info_list($projects, $theme_data, 'theme', TRUE, $additional_whitelist);
if (variable_get('locale_translation_check_disabled', 0)) {
if ($config->get('translation.check_disabled_modules')) {
update_process_info_list($projects, $module_data, 'module', FALSE, $additional_whitelist);
update_process_info_list($projects, $theme_data, 'theme', FALSE, $additional_whitelist);
}
......@@ -195,6 +203,7 @@ function locale_translation_project_list() {
* Modify .info file data before it is processed by update_process_info_list().
* In order for update_process_info_list() to recognize a project, it requires
* the 'project' parameter in the .info file data.
*
* Custom modules or themes can bring their own gettext translation file. To
* enable import of this file the module or theme defines "interface translation
* project = myproject" in its .info file. This function will add a project
......@@ -210,13 +219,9 @@ function locale_translation_project_list() {
*/
function _locale_translation_prepare_project_list($data, $type) {
foreach ($data as $name => $file) {
// Include interface translation projects.
// Custom modules can bring their own gettext translation file.
// To enable import of this file the module must define
// 'interface translation project = myproject' in its .info file.
// To allow update_process_info_list() to identify this as a project
// the 'project' property is filled with the 'interface translation project'
// value.
// Include interface translation projects. To allow
// update_process_info_list() to identify this as a project the 'project'
// property is filled with the 'interface translation project' value.
if (isset($file->info['interface translation project'])) {
$data[$name]->info['project'] = $file->info['interface translation project'];
}
......@@ -232,8 +237,9 @@ function _locale_translation_prepare_project_list($data, $type) {
* - "server_pattern": URL containing po file pattern.
*/
function locale_translation_default_translation_server() {
$config = config('locale.settings');
return array(
'pattern' => variable_get('locale_translation_default_server_pattern', LOCALE_TRANSLATION_DEFAULT_SERVER_PATTERN),
'pattern' => $config->get('translation.default_server_pattern'),
);
}
......
......@@ -32,9 +32,6 @@ function locale_uninstall() {
variable_del('locale_cache_length');
variable_del('locale_translation_plurals');
variable_del('locale_translation_javascript');
variable_del('locale_translation_test_system_info_alter');
variable_del('locale_translation_check_disabled');
variable_del('locale_translation_default_server_pattern');
// Remove all node type language variables. Node module might have been
// enabled, but may be disabled, so use a wildcard delete.
......@@ -172,20 +169,22 @@ function locale_schema() {
'not null' => TRUE,
),
'project_type' => array(
'description' => 'Project type, may be core, module, theme',
'description' => 'Project type: core, module, or theme.',
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
),
'core' => array(
'description' => 'Core compatibility string for this project.',
// http://drupal.org/node/542202#core has an example.
'description' => 'Core compatibility string for this project, for example: 8.x',
'type' => 'varchar',
'length' => 4,
'not null' => TRUE,
'default' => '',
),
'version' => array(
'description' => 'The version release of the project.',
// http://drupal.org/node/467026 has examples.
'description' => 'The version release of the project, for example: 8.x-2.1 or 8.x-1.0-dev',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
......@@ -199,7 +198,8 @@ function locale_schema() {
'default' => '',
),
'status' => array(
'description' => 'The update status of the project.',
// locale.compare.inc gives possible values for status.
'description' => 'The status of the project. Possible values are: 1 = enabled, 0 = disabled.',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
......@@ -679,59 +679,9 @@ function locale_update_8010() {
*/
function locale_update_8011() {
// Add a 'locale' cache table.
db_create_table('cache_locale', array(
'description' => 'Cache table for the locale module to store various data.',
'fields' => array(
'cid' => array(
'description' => 'Primary Key: Unique cache ID.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'data' => array(
'description' => 'A collection of data to cache.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
'expire' => array(
'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'A Unix timestamp indicating when the cache entry was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'serialized' => array(
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
'tags' => array(
'description' => 'Space-separated list of cache tags for this entry.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'checksum' => array(
'description' => 'The tag invalidation sum when this entry was saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'expire' => array('expire'),
),
'primary key' => array('cid'),
));
$locale_cache_schema = system_schema_cache_8007();
$locale_cache_schema['description'] = 'Cache table for the locale module to store various data.';
db_create_table('cache_locale', $locale_cache_schema);
// Add locale_project table.
db_create_table('locale_project', array(
......
<?php
/**
* @file
* Install, update and uninstall functions for the locale_test module.
*/
/**
* Implements hook_uninstall().
*/
function locale_test_uninstall() {
// Clear variables.
variable_del('locale_translation_test_system_info_alter');
}
......@@ -21,7 +21,7 @@ function locale_test_system_info_alter(&$info, $file, $type) {
}
if ($file->name == 'locale_test' || $file->name == 'locale_test_disabled') {
// Make the module appear as not-disabled.
// Make the module appear as unhidden.
$info['hidden'] = FALSE;
}
}
......@@ -2,5 +2,5 @@
/**
* @file
* Simulate a disabled contrib for Locale test scripts.
* Simulate a disabled contrib module for Locale test scripts.
*/
......@@ -1472,6 +1472,68 @@ function system_schema() {
return $schema;
}
/**
* The cache schema corresponding to Drupal 8.0.
*
* Helper function to add cache tables in the Drupal 7 to 8 upgrade path
* without relying on system_schema(), which may change with future updates.
*/
function system_schema_cache_8007() {
return array(
'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
'fields' => array(
'cid' => array(
'description' => 'Primary Key: Unique cache ID.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'data' => array(
'description' => 'A collection of data to cache.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
'expire' => array(
'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'A Unix timestamp indicating when the cache entry was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'serialized' => array(
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
'tags' => array(
'description' => 'Space-separated list of cache tags for this entry.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'checksum' => array(
'description' => 'The tag invalidation sum when this entry was saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'expire' => array('expire'),
),
'primary key' => array('cid'),
);
}
// Updates for core.
function system_update_last_removed() {
......
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