diff --git a/core/modules/locale/lib/Drupal/locale/Gettext.php b/core/modules/locale/lib/Drupal/locale/Gettext.php index b21023a..40472f0 100644 --- a/core/modules/locale/lib/Drupal/locale/Gettext.php +++ b/core/modules/locale/lib/Drupal/locale/Gettext.php @@ -53,7 +53,7 @@ static function filesToArray($langcode, array $files) { * * @param stdClass $file * File object with an URI property pointing at the file's path. - * - "langcode": The language the language the strings will be added to. + * - "langcode": The language the strings will be added to. * - "uri": File URI. * @param array $options * An array with options that can have the following elements: diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php index 07a1887..b7d3d50 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php @@ -58,7 +58,7 @@ public static function getInfo() { } /** - * Setup the test environment. + * Set up the test environment. * * We use German as default test language. Due to hardcoded configurations in * the locale_test module, the language can not be chosen randomly. @@ -71,7 +71,7 @@ function setUp() { $this->drupalLogin($admin_user); $this->drupalPost('admin/config/regional/language/add', array('predefined_langcode' => 'de'), t('Add language')); - // Setup timestamps to identify old and new translation sources. + // Set up timestamps to identify old and new translation sources. $this->timestamp_old = REQUEST_TIME - 300; $this->timestamp_medium = REQUEST_TIME - 200; $this->timestamp_new = REQUEST_TIME - 100; @@ -79,7 +79,7 @@ function setUp() { } /** - * Set the value of the default translations directory. + * Sets the value of the default translations directory. * * @param string $path * Path of the translations directory relative to the drupal installation @@ -92,7 +92,7 @@ private function setTranslationsDirectory($path) { } /** - * Add a language. + * Adds a language. * * @param $langcode * The language code of the language to add. @@ -115,7 +115,8 @@ function addLanguage($langcode) { * Timestamp to set the file to. Defaults to current time. * @param array $translations * Array of source/target value translation strings. Only singular strings - * are supported, no plurals. + * are supported, no plurals. No double quotes are allowed in source and + * translations strings. */ private function makePoFile($path, $filename, $timestamp = NULL, $translations = array()) { $timestamp = $timestamp ? $timestamp : REQUEST_TIME; @@ -155,7 +156,7 @@ private function makePoFile($path, $filename, $timestamp = NULL, $translations = } /** - * Setup the environment containting local and remote translation files. + * Set up the environment containting local and remote translation files. * * Update tests require a simulated environment for local and remote files. * Normally remote files are located at a remote server (e.g. ftp.drupal.org). @@ -216,7 +217,7 @@ private function setTranslationFiles() { } /** - * Setup existing translations in the database and setup the status of + * Set up existing translations in the database and set up the status of * existing translations. */ private function setCurrentTranslations() { @@ -227,7 +228,6 @@ private function setCurrentTranslations() { 'March' => 'Marz', 'June' => 'Juni', ); - $customized = 0; foreach ($non_customized_translations as $source => $translation) { $string = locale_storage()->createString(array('source' => $source, 'context' => $context)) ->save(); @@ -235,7 +235,7 @@ private function setCurrentTranslations() { 'lid' => $string->getId(), 'language' => $langcode, 'translation' => $translation, - 'customized' => $customized, + 'customized' => LOCALE_NOT_CUSTOMIZED, ))->save(); } @@ -245,7 +245,6 @@ private function setCurrentTranslations() { 'February' => 'Februar_customized', 'May' => 'Mai_customized', ); - $customized = 1; foreach ($customized_translations as $source => $translation) { $string = locale_storage()->createString(array('source' => $source, 'context' => $context)) ->save(); @@ -253,7 +252,7 @@ private function setCurrentTranslations() { 'lid' => $string->getId(), 'language' => $langcode, 'translation' => $translation, - 'customized' => $customized, + 'customized' => LOCALE_CUSTOMIZED, ))->save(); } @@ -291,35 +290,38 @@ private function setCurrentTranslations() { } /** - * Check the translation of an array of strings. + * Checks the translation of a string. * * @param string $source * Translation source string * @param string $translation * Translation to check. Use empty string to check for a not existing * translation. - * @param $langcode + * @param string $langcode * Language code of the language to translate to. + * @param string $message + * (optional) A message to display with the assertion. */ function assertTranslation($source, $translation, $langcode, $message = '') { $db_translation = db_query('SELECT translation FROM {locales_target} lt INNER JOIN {locales_source} ls ON ls.lid = lt.lid WHERE ls.source = :source AND lt.language = :langcode', array(':source' => $source, ':langcode' => $langcode))->fetchField(); - $this->assertEqual((string) $translation, (string) $db_translation, $message ? $message : format_string('Correct translation of %source (%language)', array('%source' => $source, '%language' => $langcode))); + $db_translation = $db_translation == FALSE ? '' : $db_translation; + $this->assertEqual($translation, $db_translation, $message ? $message : format_string('Correct translation of %source (%language)', array('%source' => $source, '%language' => $langcode))); } /** - * Check if a list of translatable projects gets build. + * Checks if a list of translatable projects gets build. */ function testUpdateProjects() { module_load_include('compare.inc', 'locale'); // Make the test modules look like a normal custom module. i.e. make the // modules not hidden. locale_test_system_info_alter() modifies the project - // info of the locale_test and locale_test_disabled modules. + // info of the locale_test and locale_test_translate modules. state()->set('locale.test_system_info_alter', TRUE); // Check if interface translation data is collected from hook_info. $projects = locale_translation_project_list(); - $this->assertFalse(isset($projects['locale_test_disabled']), 'Hidden module not found'); + $this->assertFalse(isset($projects['locale_test_translate']), 'Hidden module not found'); $this->assertEqual($projects['locale_test']['info']['interface translation server pattern'], 'core/modules/locale/test/test.%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'))); } @@ -341,7 +343,7 @@ function testUpdateProjectsHidden() { $this->drupalPost('admin/config/regional/translate/settings', $edit, t('Save configuration')); $projects = locale_translation_project_list(); - $this->assertTrue(isset($projects['locale_test_disabled']), 'Disabled module found'); + $this->assertTrue(isset($projects['locale_test_translate']), 'Disabled module found'); $this->assertTrue(isset($projects['locale_test']), 'Enabled module found'); } @@ -350,20 +352,19 @@ function testUpdateProjectsHidden() { * * The translation status process by default checks the status of the * installed projects. For testing purpose a predefined set of modules with - * fixed file names and release versions is used. Using a - * hook_locale_translation_projects_alter implementation in the locale_test - * module this custom project definition is applied. + * fixed file names and release versions is used. This custom project + * definition is applied using a hook_locale_translation_projects_alter + * implementation in the locale_test module. * * This test generates a set of local and remote translation files in their * respective local and remote translation directory. The test checks whether * the most recent files are selected in the different check scenarios: check - * for local files only, check for remote files only, check for both local and - * remote files. + * for local files only, check for both local and remote files. */ function testUpdateCheckStatus() { $config = config('locale.settings'); - // A flag is set to let the locale_test module replace the project data with - // a set of test projects. + // Set a flag to let the locale_test module replace the project data with a + // set of test projects. state()->set('locale.test_projects_alter', TRUE); // Create local and remote translations files. @@ -377,15 +378,14 @@ function testUpdateCheckStatus() { $this->drupalPost('admin/config/regional/translate/settings', $edit, t('Save configuration')); // Get status of translation sources at local file system. - $config->set('translation.use_source', LOCALE_TRANSLATION_USE_SOURCE_LOCAL)->save(); $this->drupalGet('admin/reports/translations/check'); $result = state()->get('locale.translation_status'); - $this->assertEqual($result['contrib_module_one']['de']->type, 'local', 'Translation of contrib_module_one found'); + $this->assertEqual($result['contrib_module_one']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of contrib_module_one found'); $this->assertEqual($result['contrib_module_one']['de']->timestamp, $this->timestamp_old, 'Translation timestamp found'); - $this->assertEqual($result['contrib_module_two']['de']->type, 'local', 'Translation of contrib_module_two found'); + $this->assertEqual($result['contrib_module_two']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of contrib_module_two found'); $this->assertEqual($result['contrib_module_two']['de']->timestamp, $this->timestamp_new, 'Translation timestamp found'); - $this->assertEqual($result['locale_test']['de']->type, 'local', 'Translation of locale_test found'); - $this->assertEqual($result['custom_module_one']['de']->type, 'local', 'Translation of custom_module_one found'); + $this->assertEqual($result['locale_test']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of locale_test found'); + $this->assertEqual($result['custom_module_one']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of custom_module_one found'); // Set the test conditions. $edit = array( @@ -398,16 +398,16 @@ function testUpdateCheckStatus() { $result = state()->get('locale.translation_status'); $this->assertEqual($result['contrib_module_one']['de']->type, 'remote', 'Translation of contrib_module_one found'); $this->assertEqual($result['contrib_module_one']['de']->timestamp, $this->timestamp_new, 'Translation timestamp found'); - $this->assertEqual($result['contrib_module_two']['de']->type, 'local', 'Translation of contrib_module_two found'); + $this->assertEqual($result['contrib_module_two']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of contrib_module_two found'); $this->assertEqual($result['contrib_module_two']['de']->timestamp, $this->timestamp_new, 'Translation timestamp found'); - $this->assertEqual($result['contrib_module_three']['de']->type, 'local', 'Translation of contrib_module_three found'); + $this->assertEqual($result['contrib_module_three']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of contrib_module_three found'); $this->assertEqual($result['contrib_module_three']['de']->timestamp, $this->timestamp_old, 'Translation timestamp found'); - $this->assertEqual($result['locale_test']['de']->type, 'local', 'Translation of locale_test found'); - $this->assertEqual($result['custom_module_one']['de']->type, 'local', 'Translation of custom_module_one found'); + $this->assertEqual($result['locale_test']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of locale_test found'); + $this->assertEqual($result['custom_module_one']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of custom_module_one found'); } /** - * Test translation import from remote sources. + * Tests translation import from remote sources. * * Test conditions: * - Source: remote and local files @@ -435,9 +435,9 @@ function testUpdateImportSourceRemote() { // Check if the translation has been updated, using the status cache. $status = state()->get('locale.translation_status'); - $this->assertEqual($status['contrib_module_one']['de']->type, 'current', 'Translation of contrib_module_one found'); - $this->assertEqual($status['contrib_module_two']['de']->type, 'current', 'Translation of contrib_module_two found'); - $this->assertEqual($status['contrib_module_three']['de']->type, 'current', 'Translation of contrib_module_three found'); + $this->assertEqual($status['contrib_module_one']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_one found'); + $this->assertEqual($status['contrib_module_two']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_two found'); + $this->assertEqual($status['contrib_module_three']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_three found'); // Check the new translation status. // The static cache needs to be flushed first to get the most recent data @@ -462,7 +462,7 @@ function testUpdateImportSourceRemote() { } /** - * Test translation import from local sources. + * Tests translation import from local sources. * * Test conditions: * - Source: local files only @@ -490,12 +490,12 @@ function testUpdateImportSourceLocal() { // Check if the translation has been updated, using the status cache. $status = state()->get('locale.translation_status'); - $this->assertEqual($status['contrib_module_one']['de']->type, 'current', 'Translation of contrib_module_one found'); - $this->assertEqual($status['contrib_module_two']['de']->type, 'current', 'Translation of contrib_module_two found'); - $this->assertEqual($status['contrib_module_three']['de']->type, 'current', 'Translation of contrib_module_three found'); + $this->assertEqual($status['contrib_module_one']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_one found'); + $this->assertEqual($status['contrib_module_two']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_two found'); + $this->assertEqual($status['contrib_module_three']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_three found'); // Check the new translation status. - // The static cache needs to be flushed firt to get the most recent data + // The static cache needs to be flushed first to get the most recent data // from the database. The function was called earlier during this test. drupal_static_reset('locale_translation_get_file_history'); $history = locale_translation_get_file_history(); @@ -517,7 +517,7 @@ function testUpdateImportSourceLocal() { } /** - * Test translation import without a translations directory. + * Tests translation import without a translations directory. * * Test conditions: * - Source: remote and local files @@ -546,12 +546,12 @@ function testUpdateImportWithoutDirectory() { // Check if the translation has been updated, using the status cache. $status = state()->get('locale.translation_status'); - $this->assertEqual($status['contrib_module_one']['de']->type, 'current', 'Translation of contrib_module_one found'); - $this->assertEqual($status['contrib_module_two']['de']->type, 'current', 'Translation of contrib_module_two found'); - $this->assertEqual($status['contrib_module_three']['de']->type, 'current', 'Translation of contrib_module_three found'); + $this->assertEqual($status['contrib_module_one']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_one found'); + $this->assertEqual($status['contrib_module_two']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_two found'); + $this->assertEqual($status['contrib_module_three']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_three found'); // Check the new translation status. - // The static cache needs to be flushed firt to get the most recent data + // The static cache needs to be flushed first to get the most recent data // from the database. The function was called earlier during this test. drupal_static_reset('locale_translation_get_file_history'); $history = locale_translation_get_file_history(); @@ -572,7 +572,7 @@ function testUpdateImportWithoutDirectory() { } /** - * Test translation import with a translations directory and only overwrite + * Tests translation import with a translations directory and only overwrite * non-customized translations. * * Test conditions: @@ -610,7 +610,7 @@ function testUpdateImportModeNonCustomized() { } /** - * Test translation import with a translations directory and don't overwrite + * Tests translation import with a translations directory and don't overwrite * any translation. * * Test conditions: @@ -648,10 +648,13 @@ function testUpdateImportModeNone() { } /** - * Test automatic translation import when a module is enabled. + * Tests automatic translation import when a module is enabled. */ function testEnableDisableModule() { - // Check is there is no translation yet. + // Make the hidden test modules look like a normal custom module. + state()->set('locale.test_system_info_alter', TRUE); + + // Check if there is no translation yet. $this->assertTranslation('Tuesday', '', 'de'); // Enable a module. @@ -661,7 +664,7 @@ function testEnableDisableModule() { $this->drupalPost('admin/modules', $edit, t('Save configuration')); // Check if translations have been imported. - $this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', + $this->assertText(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 7, '%update' => 0, '%delete' => 0)), 'One translation file imported.'); $this->assertTranslation('Tuesday', 'Dienstag', 'de'); @@ -684,31 +687,34 @@ function testEnableDisableModule() { } /** - * Test automatic translation import when a langauge is enabled. + * Tests automatic translation import when a langauge is enabled. * * When a language is added, the system will check for translations files of * enabled modules and will import them. When a language is removed the system - * will remove all translations of that langague from the database. + * will remove all translations of that langugue from the database. */ function testEnableDisableLanguage() { + // Make the hidden test modules look like a normal custom module. + state()->set('locale.test_system_info_alter', TRUE); + // Enable a module. $edit = array( 'modules[Testing][locale_test_translate][enable]' => 'locale_test_translate', ); $this->drupalPost('admin/modules', $edit, t('Save configuration')); - // Check is there is no Dutch translation yet. + // Check if there is no Dutch translation yet. $this->assertTranslation('Extraday', '', 'nl'); $this->assertTranslation('Tuesday', 'Dienstag', 'de'); - // Add a language + // Add a language. $edit = array( 'predefined_langcode' => 'nl', ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); // Check if the right number of translations are added. - $this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', + $this->assertText(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 8, '%update' => 0, '%delete' => 0)), 'One language added.'); $this->assertTranslation('Extraday', 'extra dag', 'nl'); @@ -716,34 +722,35 @@ function testEnableDisableLanguage() { $result = db_query("SELECT project FROM {locale_file} WHERE langcode='nl'")->fetchField(); $this->assertTrue((boolean) $result, 'Files removed from file history'); - // Remove a language + // Remove a language. $this->drupalPost('admin/config/regional/language/delete/nl', array(), t('Delete')); // Check if the language data is removed from the database. $result = db_query("SELECT project FROM {locale_file} WHERE langcode='nl'")->fetchField(); $this->assertFalse($result, 'Files removed from file history'); - // Check is there is no more Duth translation. + // Check that the Dutch translation is gone. $this->assertTranslation('Extraday', '', 'nl'); $this->assertTranslation('Tuesday', 'Dienstag', 'de'); } -} + /** + * Tests automatic translation import when a custom langauge is enabled. + */ + function testEnableCustomLanguage() { + // Make the hidden test modules look like a normal custom module. + state()->set('locale.test_system_info_alter', TRUE); -/* - function testAutomaticModuleTranslationImportLanguageEnable() { // Enable a module. $edit = array( 'modules[Testing][locale_test_translate][enable]' => 'locale_test_translate', ); $this->drupalPost('admin/modules', $edit, t('Save configuration')); - // Code for the language - manually set to match the test translation file. + // Create and enable a custom language with language code 'xx' and a random + // name. $langcode = 'xx'; - // The English name for the language. $name = $this->randomName(16); - - // Create a custom language. $edit = array( 'predefined_langcode' => 'custom', 'langcode' => $langcode, @@ -752,12 +759,12 @@ function testAutomaticModuleTranslationImportLanguageEnable() { ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); - // Ensure the translation file was automatically imported when language was - // added. + // Ensure the translation file is automatically imported when the language + // was added. $this->assertText(t('One translation file imported.'), t('Language file automatically imported.')); - $this->assertText(t('A translation string was skipped because of disallowed or malformed HTML'), t('Language file automatically imported.')); + $this->assertText(t('One translation string was skipped because of disallowed or malformed HTML'), t('Language file automatically imported.')); - // Ensure strings were successfully imported. + // Ensure the strings were successfully imported. $search = array( 'string' => 'lundi', 'langcode' => $langcode, @@ -766,7 +773,7 @@ function testAutomaticModuleTranslationImportLanguageEnable() { $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); $this->assertNoText(t('No strings available.'), t('String successfully imported.')); - // Ensure multiline string was imported. + // Ensure the multiline string was imported. $search = array( 'string' => 'Source string for multiline translation', 'langcode' => $langcode, @@ -787,4 +794,4 @@ function testAutomaticModuleTranslationImportLanguageEnable() { $this->assertText('Allowed HTML source string', t('String successfully imported.')); $this->assertNoText('Another allowed HTML source string', t('String with disallowed translation not imported.')); } -*/ \ No newline at end of file +} diff --git a/core/modules/locale/locale.batch.inc b/core/modules/locale/locale.batch.inc index 7bb35ef..e086869 100644 --- a/core/modules/locale/locale.batch.inc +++ b/core/modules/locale/locale.batch.inc @@ -8,6 +8,8 @@ /** * Load the common translation API. */ +// @todo Combine functions differently in files to avoid unnecessary includes. +// Follow-up issue http://drupal.org/node/1834298 require_once DRUPAL_ROOT . '/core/modules/locale/locale.translation.inc'; /** @@ -29,8 +31,8 @@ function locale_translation_batch_status_fetch_remote($source, &$context) { // Check the translation file at the remote server and update the source // data with the remote status. - if (isset($source->files['remote'])) { - $remote_file = $source->files['remote']; + if (isset($source->files[LOCALE_TRANSLATION_REMOTE])) { + $remote_file = $source->files[LOCALE_TRANSLATION_REMOTE]; $result = locale_translation_http_check($remote_file->uri); if ($result) { @@ -40,7 +42,7 @@ function locale_translation_batch_status_fetch_remote($source, &$context) { if (isset($result->updated)) { $remote_file->uri = isset($result->redirect_uri) ? $result->redirect_uri : $remote_file->uri; $remote_file->timestamp = $result->updated; - $source->files['remote'] = $remote_file; + $source->files[LOCALE_TRANSLATION_REMOTE] = $remote_file; } // Record success. $context['results']['files'][$source->name] = $source->name; @@ -74,13 +76,13 @@ function locale_translation_batch_status_fetch_local($sources, &$context) { // Get the status of local translation files and store the result data in the // batch results for later processing. foreach ($sources as $source) { - if (isset($source->files['local'])) { + if (isset($source->files[LOCALE_TRANSLATION_LOCAL])) { locale_translation_source_check_file($source); // If remote data was collected before, we merge it into the newly // collected result. if (isset($context['results']['sources'][$source->name][$source->langcode])) { - $source->files['remote'] = $context['results']['sources'][$source->name][$source->langcode]->files['remote']; + $source->files[LOCALE_TRANSLATION_REMOTE] = $context['results']['sources'][$source->name][$source->langcode]->files[LOCALE_TRANSLATION_REMOTE]; } // Record success and store the updated source data. @@ -113,26 +115,26 @@ function locale_translation_batch_status_compare(&$context) { if (isset($context['results']['sources'])) { foreach ($context['results']['sources'] as $project => $langcodes) { foreach ($langcodes as $langcode => $source) { - $local = isset($source->files['local']) ? $source->files['local'] : NULL; - $remote = isset($source->files['remote']) ? $source->files['remote'] : NULL; + $local = isset($source->files[LOCALE_TRANSLATION_LOCAL]) ? $source->files[LOCALE_TRANSLATION_LOCAL] : NULL; + $remote = isset($source->files[LOCALE_TRANSLATION_REMOTE]) ? $source->files[LOCALE_TRANSLATION_REMOTE] : NULL; - // The available translation files are compare and data of the most recent - // file is used to update the source object. + // The available translation files are compared and data of the most + // recent file is used to update the source object. $file = _locale_translation_source_compare($local, $remote) == LOCALE_TRANSLATION_SOURCE_COMPARE_LT ? $remote : $local; if (isset($file->timestamp)) { $source->type = $file->type; $source->timestamp = $file->timestamp; } - // Compare the available translation with the current translations status. - // If the project/language was translated before and it is more recent - // than the most recent translation, the translation is up to date. Which - // is marked in the source object with type "current". + // Compare the available translation with the current translations + // status. If the project/language was translated before and it is more + // recent than the most recent translation, the translation is up to + // date. Which is marked in the source object with type "current". if (isset($history[$source->project][$source->langcode])) { $current = $history[$source->project][$source->langcode]; // Add the current translation to the source object to save it in // the status cache. - $source->files['current'] = $current; + $source->files[LOCALE_TRANSLATION_CURRENT] = $current; if (isset($source->type)) { $available = $source->files[$source->type]; @@ -191,7 +193,7 @@ function locale_translation_batch_status_finished($success, $results) { } /** - * Load translation source data for the projects to be updated. + * Loads translation source data for the projects to be updated. * * Source data is loaded from cache and stored in the context results array. * Source data contains the translations status per project / per language @@ -200,10 +202,10 @@ function locale_translation_batch_status_finished($success, $results) { * so that other batch operations can take this data as input for their * operation. * - * @see locale_translation_batch_fetch_download(). - * @see locale_translation_batch_fetch_import(). - * @see locale_translation_batch_fetch_update_status(). - * @see locale_translation_batch_status_compare(). + * @see locale_translation_batch_fetch_download() + * @see locale_translation_batch_fetch_import() + * @see locale_translation_batch_fetch_update_status() + * @see locale_translation_batch_status_compare() */ function locale_translation_batch_fetch_sources($projects, $langcodes, &$context) { $context['results']['input'] = locale_translation_load_sources($projects, $langcodes); @@ -230,23 +232,23 @@ function locale_translation_batch_fetch_sources($projects, $langcodes, &$context * @param $context * Batch context array. * - * @see locale_translation_batch_fetch_sources(). - * @see locale_translation_batch_fetch_import(). - * @see locale_translation_batch_fetch_update_status(). - * @see locale_translation_batch_status_compare(). + * @see locale_translation_batch_fetch_sources() + * @see locale_translation_batch_fetch_import() + * @see locale_translation_batch_fetch_update_status() + * @see locale_translation_batch_status_compare() */ function locale_translation_batch_fetch_download($project, $langcode, &$context) { $sources = $context['results']['input']; if (isset($sources[$project . ':' . $langcode])) { $source = $sources[$project . ':' . $langcode]; - if (isset($source->type) && $source->type == 'remote') { + if (isset($source->type) && $source->type == LOCALE_TRANSLATION_REMOTE) { $t = get_t(); - if ($file = locale_translation_download_source($source->files['remote'])) { + if ($file = locale_translation_download_source($source->files[LOCALE_TRANSLATION_REMOTE])) { $context['message'] = $t('Importing: %name.', array('%name' => $file->filename)); - $source->files['download'] = $file; + $source->files[LOCALE_TRANSLATION_DOWNLOADED] = $file; } else { - $context['results']['failed_files'][] = $source->files['remote']; + $context['results']['failed_files'][] = $source->files[LOCALE_TRANSLATION_REMOTE]; } $context['results']['sources'][$project][$langcode] = $source; } @@ -256,7 +258,7 @@ function locale_translation_batch_fetch_download($project, $langcode, &$context) /** * Batch process: Import translation file. * - * This batch operations imports either a local gettext file or a downloaded + * This batch operation imports either a local gettext file or a downloaded * remote gettext file. In case of a downloaded file the location of the * temporary file is found in the $context['results']['sources']. The temporary * file will be deleted after importing or will be moved to the local @@ -272,30 +274,30 @@ function locale_translation_batch_fetch_download($project, $langcode, &$context) * @param $context * Batch context array. * - * @see locale_translate_batch_import_files(). - * @see locale_translation_batch_fetch_sources(). - * @see locale_translation_batch_fetch_download(). - * @see locale_translation_batch_fetch_update_status(). - * @see locale_translation_batch_status_compare(). + * @see locale_translate_batch_import_files() + * @see locale_translation_batch_fetch_sources() + * @see locale_translation_batch_fetch_download() + * @see locale_translation_batch_fetch_update_status() + * @see locale_translation_batch_status_compare() */ function locale_translation_batch_fetch_import($project, $langcode, $options, &$context) { $sources = $context['results']['input']; if (isset($sources[$project . ':' . $langcode])) { $source = $sources[$project . ':' . $langcode]; if (isset($source->type)) { - if ($source->type == 'remote' || $source->type == 'local') { + if ($source->type == LOCALE_TRANSLATION_REMOTE || $source->type == LOCALE_TRANSLATION_LOCAL) { $t = get_t(); - // If we are working on a remote file we will import the downloaded file and - // use the result data from the - if ($source->type == 'remote') { - if (isset($context['results']['sources'][$source->project][$source->langcode]->files['download'])) { - $import_type = 'download'; + // If we are working on a remote file we will import the downloaded + // file. If the file was local just mark the result as such. + if ($source->type == LOCALE_TRANSLATION_REMOTE) { + if (isset($context['results']['sources'][$source->project][$source->langcode]->files[LOCALE_TRANSLATION_DOWNLOADED])) { + $import_type = LOCALE_TRANSLATION_DOWNLOADED; $source_result = $context['results']['sources'][$source->project][$source->langcode]; } } else { - $import_type = 'local'; + $import_type = LOCALE_TRANSLATION_LOCAL; $source_result = $source; } @@ -314,43 +316,43 @@ function locale_translation_batch_fetch_import($project, $langcode, $options, &$ if (isset($context['results']['files'][$file->uri])) { $context['message'] = $t('Imported: %name.', array('%name' => $file->filename)); - // Keep the data of imported source. In following batch operations - // it will be saved in the {locale_file} table. - $source_result->files['import'] = $source_result->files[$source->type]; - - // Downloaded files are stored in the temporary files directory. On - // succesfull import, the files are moved to the local destination - // directory if files should be kept locally. Otherwise the - // temporary files are deleted. - if ($import_type == 'download' && variable_get('locale_translate_file_directory', conf_path() . '/files/translations') && isset($source_result->files['local'])) { - // Move the temporary file to the local translations directory. - if (file_unmanaged_move($file->uri, $source_result->files['local']->uri, FILE_EXISTS_REPLACE)) { + // Keep the data of imported source. In the following batch + // operation it will be saved in the {locale_file} table. + $source_result->files[LOCALE_TRANSLATION_IMPORTED] = $source_result->files[$source->type]; + + // Downloaded files are stored in the temporary files directory. If + // files should be kept locally, they will be moved to the local + // translations after successfull import. Otherwise the temporary + // file is are deleted after being imported. + if ($import_type == LOCALE_TRANSLATION_DOWNLOADED && variable_get('locale_translate_file_directory', conf_path() . '/files/translations') && isset($source_result->files[LOCALE_TRANSLATION_LOCAL])) { + if (file_unmanaged_move($file->uri, $source_result->files[LOCALE_TRANSLATION_LOCAL]->uri, FILE_EXISTS_REPLACE)) { // The downloaded file is now moved to the local file location. // From this point forward we can treat it as if we imported a // local file. - $import_type = 'local'; + $import_type = LOCALE_TRANSLATION_LOCAL; } } - if ($import_type == 'download') { - // The temporary file is now imported and will not be used further. - // Store the timestamp and delete the file. + // The downloaded file is imported but will not be stored locally. + // Store the timestamp and delete the file. + if ($import_type == LOCALE_TRANSLATION_DOWNLOADED) { $timestamp = filemtime($source_result->files[$import_type]->uri); - $source_result->files['import']->timestamp = $timestamp; - $source_result->files['import']->last_checked = REQUEST_TIME; + $source_result->files[LOCALE_TRANSLATION_IMPORTED]->timestamp = $timestamp; + $source_result->files[LOCALE_TRANSLATION_IMPORTED]->last_checked = REQUEST_TIME; file_unmanaged_delete($file->uri); } - if ($import_type == 'local') { - // Import type is 'local'. + // If the translation file is stored in the local directory. The + // timestamp of the file is stored. + if ($import_type == LOCALE_TRANSLATION_LOCAL) { $timestamp = filemtime($source_result->files[$import_type]->uri); - $source_result->files['local']->timestamp = $timestamp; - $source_result->files['import']->timestamp = $timestamp; - $source_result->files['import']->last_checked = REQUEST_TIME; + $source_result->files[LOCALE_TRANSLATION_LOCAL]->timestamp = $timestamp; + $source_result->files[LOCALE_TRANSLATION_IMPORTED]->timestamp = $timestamp; + $source_result->files[LOCALE_TRANSLATION_IMPORTED]->last_checked = REQUEST_TIME; } } else { // File import failed. We can delete the temporary file. - if ($import_type == 'download') { + if ($import_type == LOCALE_TRANSLATION_DOWNLOADED) { file_unmanaged_delete($file->uri); } } @@ -370,10 +372,10 @@ function locale_translation_batch_fetch_import($project, $langcode, $options, &$ * @param $context * Batch context array. * - * @see locale_translation_batch_fetch_sources(). - * @see locale_translation_batch_fetch_download(). - * @see locale_translation_batch_fetch_import(). - * @see locale_translation_batch_status_compare(). + * @see locale_translation_batch_fetch_sources() + * @see locale_translation_batch_fetch_download() + * @see locale_translation_batch_fetch_import() + * @see locale_translation_batch_status_compare() */ function locale_translation_batch_fetch_update_status(&$context) { $results = array(); @@ -383,20 +385,20 @@ function locale_translation_batch_fetch_update_status(&$context) { foreach ($langcodes as $langcode => $source) { // Store the state of the imported translations in {locale_file} table. - // During the batch execution data of imported files is temporary stored - // in $context['results']['sources']. Now is will be stored in the - // database. Afterwards the temporary import and download data can be - // deleted. - if (isset($source->files['import'])) { - $file = $source->files['import']; + // During the batch execution the data of the imported files is + // temporary stored in $context['results']['sources']. Now it will be + // stored in the database. Afterwards the temporary import and download + // data can be deleted. + if (isset($source->files[LOCALE_TRANSLATION_IMPORTED])) { + $file = $source->files[LOCALE_TRANSLATION_IMPORTED]; locale_translation_update_file_history($file); - unset($source->files['import']); + unset($source->files[LOCALE_TRANSLATION_IMPORTED]); } - unset($source->files['download']); + unset($source->files[LOCALE_TRANSLATION_DOWNLOADED]); // The source data is now up to date. Data of local and/or remote source // file is up to date including an updated time stamp. In a next batch - // operation this can be use to update the translation status. + // operation this can be used to update the translation status. $context['results']['sources'][$project][$langcode] = $source; } } @@ -406,9 +408,9 @@ function locale_translation_batch_fetch_update_status(&$context) { /** * Batch finished callback: Set result message. * - * @param $success + * @param boolean $success * TRUE if batch succesfully completed. - * @param $results + * @param array * Batch results. */ function locale_translation_batch_fetch_finished($success, $results) { @@ -459,7 +461,7 @@ function locale_translation_http_check($uri, $headers = array()) { } /** - * Download source file from a remote server. + * Downloads source file from a remote server. * * The downloaded file is stored in the temporary files directory. * @@ -480,11 +482,11 @@ function locale_translation_download_source($source_file) { $file->project = $source_file->project; $file->langcode = $source_file->langcode; $file->version = $source_file->version; - $file->type = 'download'; + $file->type = LOCALE_TRANSLATION_DOWNLOADED; $file->uri = $uri; $file->filename = $source_file->filename; return $file; } - watchdog('locale', 'Unable to download translation file @uri.', array('@uri' => $source->files['remote']->uri), WATCHDOG_ERROR); + watchdog('locale', 'Unable to download translation file @uri.', array('@uri' => $source->files[LOCALE_TRANSLATION_REMOTE]->uri), WATCHDOG_ERROR); return FALSE; } diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 586d626..46c5453 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -428,8 +428,8 @@ function locale_translate_batch_import($file, $options, &$context) { } // Add the reported values to the statistics for this file. - // Each import itteration reports statistics in an array. The results of - // each itteration are added and merged here and stored per file. + // Each import iteration reports statistics in an array. The results of + // each iteration are added and merged here and stored per file. if (!isset($context['results']['stats']) || !isset($context['results']['stats'][$file->uri])) { $context['results']['stats'][$file->uri] = array(); } @@ -463,10 +463,11 @@ function locale_translate_batch_import($file, $options, &$context) { function locale_translate_batch_import_save($context) { if (isset($context['results']['files'])) { foreach ($context['results']['files'] as $file) { - // Update the file history if both project and version are known. This table - // is used by the automated translation update function which tracks - // translation status of module and themes in the system. Other data - // than installed projects would stay in the table for ever never. + // Update the file history if both project and version are known. This + // table is used by the automated translation update function which tracks + // translation status of module and themes in the system. Other + // translation files are not tracked and are therefore not stored in this + // table. if ($file->project && $file->version) { $file->last_checked = REQUEST_TIME; locale_translation_update_file_history($file); @@ -613,7 +614,6 @@ function locale_translate_file_attach_properties($file, $options = array()) { * TRUE if files are removed sucessfully. FALSE if one or more files could * not be deleted. */ -// @todo Move this function to translation.inc? function locale_translate_delete_translation_files($projects = array(), $langcodes = array()) { $fail = FALSE; locale_translation_file_history_delete($projects, $langcodes); diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index 333ee53..86d6acf 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -10,6 +10,8 @@ /** * Load the common translation API. */ +// @todo Combine functions differently in files to avoid unnecessary includes. +// Follow-up issue http://drupal.org/node/1834298 require_once DRUPAL_ROOT . '/core/modules/locale/locale.translation.inc'; /** @@ -273,7 +275,7 @@ function locale_translation_check_projects_batch($projects = array(), $langcodes } /** - * Build a batch to get the status of remote and local translation files. + * Builds a batch to get the status of remote and local translation files. * * The batch process fetches the state of both remote and (if configured) local * translation files. The data of the most recent translation is stored per @@ -307,7 +309,8 @@ function locale_translation_batch_status_build($projects = array(), $langcodes = } /** - * Helper function to construct batch operations checking remote translation status. + * Helper function to construct batch operations checking remote translation + * status. * * @param array projects * Array of project names to be processed. @@ -378,7 +381,7 @@ function locale_translation_check_projects_local($projects = array(), $langcodes $current = $history[$source->project][$source->langcode]; // Add the current translation to the source object to save it in // the status cache. - $source->files['current'] = $current; + $source->files[LOCALE_TRANSLATION_CURRENT] = $current; if (isset($source->type)) { $available = $source->files[$source->type]; diff --git a/core/modules/locale/locale.fetch.inc b/core/modules/locale/locale.fetch.inc index e5278e7..b65aa4b 100755 --- a/core/modules/locale/locale.fetch.inc +++ b/core/modules/locale/locale.fetch.inc @@ -8,10 +8,12 @@ /** * Load the common translation API. */ +// @todo Combine functions differently in files to avoid unnecessary includes. +// Follow-up issue http://drupal.org/node/1834298 require_once DRUPAL_ROOT . '/core/modules/locale/locale.translation.inc'; /** - * Build a batch to check, download and import project translations. + * Builds a batch to check, download and import project translations. * * @param array $projects * Array of project names for which to update the translations. Defaults to @@ -25,7 +27,6 @@ * Batch definition array. */ function locale_translation_batch_update_build($projects = array(), $langcodes = array(), $options = array()) { - // @todo Merge compare.inc and fetch.inc? Merge with batch.inc? module_load_include('compare.inc', 'locale'); $t = get_t(); $projects = $projects ? $projects : array_keys(locale_translation_get_projects()); @@ -46,7 +47,7 @@ function locale_translation_batch_update_build($projects = array(), $langcodes = } /** - * Build a batch to download and import project translations. + * Builds a batch to download and import project translations. * * @param array $projects * Array of project names for which to check the state of translation files. diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index fde8d6a..3b26178 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -708,7 +708,6 @@ function locale_update_8010() { 'default' => '', ), 'uri' => array( - 'description' => 'File system path for importing the file.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, @@ -850,11 +849,9 @@ function locale_update_8015() { 'description' => 'Version tag of the imported file.', ), 'uri' => array( - 'type' => 'varchar', - 'length' => 255, + 'description' => 'File system path for importing the file.', + 'type' => 'text', 'not null' => TRUE, - 'default' => '', - 'description' => 'URI of the remote file, the resulting local file or the locally imported file.', ), 'timestamp' => array( 'type' => 'int', diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index db230ff..8b7235c 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -115,6 +115,30 @@ */ const LOCALE_TRANSLATION_OVERWRITE_NONE = 'none'; +/** + * Translation source is a remote file. + */ +const LOCALE_TRANSLATION_REMOTE = 'remote'; + +/** + * Translation source is a local file. + */ +const LOCALE_TRANSLATION_LOCAL = 'local'; + +/** + * Translation source is the current translation. + */ +const LOCALE_TRANSLATION_CURRENT = 'current'; + +/** + * Translation source is a downloaded file. + */ +const LOCALE_TRANSLATION_DOWNLOADED = 'download'; + +/** + * Translation source is an imported file. + */ +const LOCALE_TRANSLATION_IMPORTED = 'import'; /** * Implements hook_help(). @@ -824,7 +848,7 @@ function locale_preprocess_node(&$variables) { } /** - * Get current translation status from the {locale_file} table. + * Gets current translation status from the {locale_file} table. * * @return array * Array of translation file objects. @@ -836,7 +860,7 @@ function locale_translation_get_file_history() { // Get file history from the database. $result = db_query('SELECT project, langcode, filename, version, uri, timestamp, last_checked FROM {locale_file}'); foreach ($result as $file) { - $file->type = 'current'; + $file->type = LOCALE_TRANSLATION_CURRENT; $history[$file->project][$file->langcode] = $file; } } @@ -844,9 +868,9 @@ function locale_translation_get_file_history() { } /** - * Update the {locale_file} table. + * Updates the {locale_file} table. * - * @param $file + * @param object $file * Object representing the file just imported. * * @return integer @@ -866,7 +890,7 @@ function locale_translation_update_file_history($file) { } /** - * Delete the history of downloaded translations. + * Deletes the history of downloaded translations. * * @param array $projects * Project name(s) to be deleted from the file history. If both project(s) and @@ -886,7 +910,7 @@ function locale_translation_file_history_delete($projects = array(), $langcodes } /** - * Save the status of translation sources in static cache. + * Saves the status of translation sources in static cache. * * @param array $data * Array of translation source data, structured by project name and langcode. diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index f0c05e6..ad9f1f6 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -562,20 +562,25 @@ function locale_translate_settings_submit($form, &$form_state) { switch ($values['overwrite']) { case LOCALE_TRANSLATION_OVERWRITE_ALL: - $config->set('translation.overwrite_customized', TRUE)->save(); - $config->set('translation.overwrite_not_customized', TRUE)->save(); + $config + ->set('translation.overwrite_customized', TRUE) + ->set('translation.overwrite_not_customized', TRUE); break; case LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED: - $config->set('translation.overwrite_customized', FALSE)->save(); - $config->set('translation.overwrite_not_customized', TRUE)->save(); + $config + ->set('translation.overwrite_customized', FALSE) + ->set('translation.overwrite_not_customized', TRUE); break; case LOCALE_TRANSLATION_OVERWRITE_NONE: - $config->set('translation.overwrite_customized', FALSE)->save(); - $config->set('translation.overwrite_not_customized', FALSE)->save(); + $config + ->set('translation.overwrite_customized', FALSE) + ->set('translation.overwrite_not_customized', FALSE); break; } - $config->set('translation.check_disabled_modules', $values['check_disabled_modules'])->save(); + $config + ->set('translation.check_disabled_modules', $values['check_disabled_modules']) + ->save(); // Invalidate the cached translation status when the configuration setting of // 'use_source' and 'check_disabled_modules' change. @@ -592,7 +597,6 @@ function locale_translate_settings_submit($form, &$form_state) { */ function locale_translation_status_form($form, &$form_state) { module_load_include('compare.inc', 'locale'); - //locale_translation_flush_projects(); $languages = locale_translatable_language_list(); $status = state()->get('locale.translation_status'); @@ -603,7 +607,7 @@ function locale_translation_status_form($form, &$form_state) { // @todo Add user interface update for translation update. // Followup issues: Display translation status http://drupal.org/node/1804702 - // and Translations update feature user experience http://drupal.org/node/1029554 + // and Translations update feature UX http://drupal.org/node/1029554 $form['langcodes'] = array( '#type' => 'value', '#value' => drupal_map_assoc(array_keys($languages)), diff --git a/core/modules/locale/locale.translation.inc b/core/modules/locale/locale.translation.inc index a250e4d..d6060f6 100644 --- a/core/modules/locale/locale.translation.inc +++ b/core/modules/locale/locale.translation.inc @@ -41,14 +41,13 @@ * disabled this function will return the last known module state. The status * will only be updated once Update module is enabled. * - * @see locale_translation_build_projects(). - * * @params array $project_names * Array of names of the projects to get. * * @return array - * Array of project data for translation update. See - * locale_translation_build_projects() for details. + * Array of project data for translation update. + * + * @see locale_translation_build_projects() */ function locale_translation_get_projects($project_names = array()) { $projects = &drupal_static(__FUNCTION__, array()); @@ -80,14 +79,14 @@ function locale_translation_get_projects($project_names = array()) { } /** - * Clear the projects cache. + * Clears the projects cache. */ function locale_translation_clear_cache_projects() { drupal_static('locale_translation_get_projects', array()); } /** - * Load cached translation sources containing current translation status. + * Loads cached translation sources containing current translation status. * * @param array $projects * Array of project names. Defaults to all translatable projects. @@ -97,7 +96,7 @@ function locale_translation_clear_cache_projects() { * @return array * Array of source objects. Keyed with :. * - * @see locale_translation_source_build(). + * @see locale_translation_source_build() */ function locale_translation_load_sources($projects = NULL, $langcodes = NULL) { $sources = array(); @@ -127,7 +126,7 @@ function locale_translation_load_sources($projects = NULL, $langcodes = NULL) { * @return array * Array of source objects. Keyed with :. * - * @see locale_translation_source_build(). + * @see locale_translation_source_build() */ function locale_translation_build_sources($projects = array(), $langcodes = array()) { $sources = array(); @@ -144,7 +143,7 @@ function locale_translation_build_sources($projects = array(), $langcodes = arra } /** - * Check whether a po file exists in the local filesystem. + * Checks whether a po file exists in the local filesystem. * * It will search in the directory set in the translation source. Which defaults * to the "translations://" stream wrapper path. The directory may contain any @@ -156,22 +155,23 @@ function locale_translation_build_sources($projects = array(), $langcodes = arra * using the server_pattern directive in the module's .info file or by using * hook_locale_translation_projects_alter(). * - * @param stdClass $source + * @param object $source * Translation source object. - * @see locale_translation_source_build() * * @return stdClass * File object (filename, basename, name) updated with data of the po file. * On success the files property of the source object is updated. - * files['local']: + * files[LOCALE_TRANSLATION_LOCAL]: * - "uri": File name and path. * - "timestamp": Last updated time of the po file. * FALSE if the file is not found. + * + * @see locale_translation_source_build() */ function locale_translation_source_check_file(&$source) { - if (isset($source->files['local'])) { - $directory = $source->files['local']->directory; - $filename = '/' . preg_quote($source->files['local']->filename) . '$/'; + if (isset($source->files[LOCALE_TRANSLATION_LOCAL])) { + $directory = $source->files[LOCALE_TRANSLATION_LOCAL]->directory; + $filename = '/' . preg_quote($source->files[LOCALE_TRANSLATION_LOCAL]->filename) . '$/'; // If the directory contains a stream wrapper, it is converted to a real // path. This is required for file_scan_directory() which can not handle @@ -182,8 +182,8 @@ function locale_translation_source_check_file(&$source) { if ($files = file_scan_directory($directory, $filename, array('key' => 'name', 'recurse' => FALSE))) { $file = current($files); - $source->files['local']->uri = $file->uri; - $source->files['local']->timestamp = filemtime($file->uri); + $source->files[LOCALE_TRANSLATION_LOCAL]->uri = $file->uri; + $source->files[LOCALE_TRANSLATION_LOCAL]->timestamp = filemtime($file->uri); return $file; } } @@ -191,14 +191,14 @@ function locale_translation_source_check_file(&$source) { } /** - * Build abstract translation source. + * Builds abstract translation source. * - * @param stdClass $project + * @param object $project * Project object. * @param string $langcode * Language code. * @param string $filename - * File name of translation file. May contains placeholders. + * File name of translation file. May contain placeholders. * * @return object * Source object: @@ -211,12 +211,16 @@ function locale_translation_source_check_file(&$source) { * - "files": Array of file objects containing properties of local and remote * translation files. * Other processes can add the following properties: - * - "type": Most recent file type 'remote' or 'local'. Corresponding with - * a key of the "files" array. + * - "type": Most recent file type LOCALE_TRANSLATION_REMOTE or + * LOCALE_TRANSLATION_LOCAL. Corresponding with a key of the + * "files" array. * - "timestamp": Timestamp of the most recent translation file. - * The "files" array can hold file objects of type: 'local', 'remote', - * 'download', 'import' and 'current'. Each contains following properties: - * - "type": The object type ('local', 'remote', etc. see above). + * The "files" array can hold file objects of type: + * LOCALE_TRANSLATION_LOCAL, LOCALE_TRANSLATION_REMOTE, + * LOCALE_TRANSLATION_DOWNLOADED, LOCALE_TRANSLATION_IMPORTED and + * LOCALE_TRANSLATION_CURRENT. Each contains following properties: + * - "type": The object type (LOCALE_TRANSLATION_LOCAL, + * LOCALE_TRANSLATION_REMOTE, etc. see above). * - "project": Project name. * - "langcode": Language code. * - "version": Project version. @@ -239,41 +243,41 @@ function locale_translation_source_build($project, $langcode, $filename = NULL) $filename = $filename ? $filename : config('locale.settings')->get('translation.default_filename'); // If the server_pattern contains a remote file path we will check for a - // remote file. The local version of this file will will only be checked is a + // remote file. The local version of this file will only be checked if a // translations directory has been defined. If the server_pattern is a local // file path we will only check for a file in the local file system. $files = array(); if (_locale_translation_file_is_remote($source->server_pattern)) { - $files['remote'] = (object) array( + $files[LOCALE_TRANSLATION_REMOTE] = (object) array( 'project' => $project->name, 'langcode' => $langcode, 'version' => $project->version, - 'type' => 'remote', + 'type' => LOCALE_TRANSLATION_REMOTE, 'filename' => locale_translation_build_server_pattern($source, basename($source->server_pattern)), 'uri' => locale_translation_build_server_pattern($source, $source->server_pattern), ); if (variable_get('locale_translate_file_directory', conf_path() . '/files/translations')) { - $files['local'] = (object) array( + $files[LOCALE_TRANSLATION_LOCAL] = (object) array( 'project' => $project->name, 'langcode' => $langcode, 'version' => $project->version, - 'type' => 'local', + 'type' => LOCALE_TRANSLATION_LOCAL, 'filename' => locale_translation_build_server_pattern($source, $filename), 'directory' => 'translations://', ); - $files['local']->uri = $files['local']->directory . $files['local']->filename; + $files[LOCALE_TRANSLATION_LOCAL]->uri = $files[LOCALE_TRANSLATION_LOCAL]->directory . $files[LOCALE_TRANSLATION_LOCAL]->filename; } } else { - $files['local'] = (object) array( + $files[LOCALE_TRANSLATION_LOCAL] = (object) array( 'project' => $project->name, 'langcode' => $langcode, 'version' => $project->version, - 'type' => 'local', + 'type' => LOCALE_TRANSLATION_LOCAL, 'filename' => locale_translation_build_server_pattern($source, basename($source->server_pattern)), 'directory' => locale_translation_build_server_pattern($source, drupal_dirname($source->server_pattern)), ); - $files['local']->uri = $files['local']->directory . '/' . $files['local']->filename; + $files[LOCALE_TRANSLATION_LOCAL]->uri = $files[LOCALE_TRANSLATION_LOCAL]->directory . '/' . $files[LOCALE_TRANSLATION_LOCAL]->filename; } $source->files = $files; @@ -303,9 +307,9 @@ function _locale_translation_file_is_remote($uri) { * The timestamp property of the source objects are used to determine which is * the newer one. * - * @param stdClass $source1 + * @param object $source1 * Source object of the first translation source. - * @param stdClass $source2 + * @param object $source2 * Source object of available update. * * @return integer @@ -337,7 +341,7 @@ function _locale_translation_source_compare($source1, $source2) { } /** - * Return default import options for translation update. + * Returns default import options for translation update. * * @return array * Array of translation import options. @@ -351,4 +355,4 @@ function _locale_translation_default_update_options() { 'customized' => $config->get('translation.overwrite_customized'), ), ); -} \ No newline at end of file +} diff --git a/core/modules/locale/tests/modules/locale_test/locale_test.module b/core/modules/locale/tests/modules/locale_test/locale_test.module index a77472f..8f87ddc 100644 --- a/core/modules/locale/tests/modules/locale_test/locale_test.module +++ b/core/modules/locale/tests/modules/locale_test/locale_test.module @@ -17,7 +17,7 @@ function locale_test_system_info_alter(&$info, $file, $type) { // To test the module detection proces by locale_project_list() the // test modules should mimic a custom module. I.e. be non-hidden. if (state()->get('locale.test_system_info_alter')) { - if ($file->name == 'locale_test' || $file->name == 'locale_test_disabled') { + if ($file->name == 'locale_test' || $file->name == 'locale_test_translate') { // Don't hide the module. $info['hidden'] = FALSE; } diff --git a/core/modules/locale/tests/modules/locale_test_disabled/locale_test_disabled.info b/core/modules/locale/tests/modules/locale_test_disabled/locale_test_disabled.info deleted file mode 100644 index 7eddf25..0000000 --- a/core/modules/locale/tests/modules/locale_test_disabled/locale_test_disabled.info +++ /dev/null @@ -1,10 +0,0 @@ -name = Disabled locale test -description = Disabled support module for locale module testing. -package = Testing -version = VERSION -core = 8.x -hidden = TRUE -project = locale_test_disabled - -; Definitions for interface translation. -interface translation project = locale_test_disabled diff --git a/core/modules/locale/tests/modules/locale_test_disabled/locale_test_disabled.module b/core/modules/locale/tests/modules/locale_test_disabled/locale_test_disabled.module deleted file mode 100644 index 0003e96..0000000 --- a/core/modules/locale/tests/modules/locale_test_disabled/locale_test_disabled.module +++ /dev/null @@ -1,6 +0,0 @@ -