diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index a9fa538..b4e8fce 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1843,6 +1843,8 @@ function install_import_translations_remaining(&$install_state) { * * @return array * The batch definition, if there are configuration objects to update. + * + * @see install_tasks() */ function install_update_configuration_translations(&$install_state) { module_load_include('bulk.inc', 'locale'); diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 3317ba4..d4d16f3 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -88,7 +88,7 @@ public function build(ContainerBuilder $container) { $container ->register('config.storage.schema', 'Drupal\Core\Config\Schema\SchemaStorage'); - // Register installer configuration storage + // Register installer configuration storage. $container ->register('config.storage.installer', 'Drupal\Core\Config\InstallStorage'); diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php index 252778d..08e44a3 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php @@ -4,6 +4,7 @@ * @file * Contains \Drupal\locale\LocaleConfigManager. */ + namespace Drupal\locale; use Drupal\Core\Language\Language; @@ -42,9 +43,10 @@ class LocaleConfigManager extends TypedConfigManager { * @param \Drupal\Core\Config\StorageInterface $schemaStorage * The storage controller object to use for reading schema data. * @param \Drupal\Core\Config\StorageInterface $installStorage - * The storage controller object to use for reading default configuration data. + * The storage controller object to use for reading default configuration + * data. * @param \Drupal\locale\StringStorageInterface $localeStorage - * (Optional) The locale storage to use for reading string translations. + * (optional) The locale storage to use for reading string translations. * Defaults to locale_storage(). */ public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, StorageInterface $installStorage, StringStorageInterface $localeStorage = NULL) { @@ -88,7 +90,7 @@ public function get($name) { * @return array * The elements of default configuration that haven't changed. */ - protected function compareConfigData($default, $updated) { + protected function compareConfigData(array $default, array $updated) { // Speed up comparison, specially for install operations. if ($default === $updated) { return $default; @@ -117,13 +119,13 @@ protected function compareConfigData($default, $updated) { * @param array $data * Configuration data to be saved, that will be only the translated values. */ - public function saveTranslationData($name, $langcode, $data) { + public function saveTranslationData($name, $langcode, array $data) { $locale_name = 'locale.config.' . $langcode . '.' . $name; $this->configStorage->write($locale_name, $data); } /** - * Save translated configuration data. + * Deletes translated configuration data. * * @param string $name * Configuration object name. @@ -145,7 +147,7 @@ public function deleteTranslationData($name, $langcode) { * @return array * Array of configuration object names. */ - public function getComponentNames($components) { + public function getComponentNames(array $components) { $components = array_filter($components); if ($components) { $names = array(); @@ -169,7 +171,7 @@ public function getComponentNames($components) { * @param array $langcodes * Array of language codes. */ - public function deleteComponentTranslations($components, $langcodes) { + public function deleteComponentTranslations(array $components, array $langcodes) { $names = $this->getComponentNames($components); if ($names && $langcodes) { foreach ($names as $name) { @@ -181,7 +183,7 @@ public function deleteComponentTranslations($components, $langcodes) { } /** - * Get configuration names associated with strings. + * Gets configuration names associated with strings. * * @param array $lids * Array with string identifiers. @@ -189,7 +191,7 @@ public function deleteComponentTranslations($components, $langcodes) { * @return array * Array of configuration object names. */ - public function getStringNames($lids) { + public function getStringNames(array $lids) { $names = array(); $locations = $this->localeStorage->getLocations(array('sid' => $lids, 'type' => 'configuration')); foreach ($locations as $location) { @@ -199,9 +201,9 @@ public function getStringNames($lids) { } /** - * Delete configuration for language. + * Deletes configuration for language. * - * @param $langcode + * @param string $langcode * Language code to delete. */ public function deleteLanguageTranslations($langcode) { @@ -214,53 +216,67 @@ public function deleteLanguageTranslations($langcode) { /** * Translates string using the localization system. * - * So far we only know how to translate strings from English so we check - * whether the source data is English. + * So far we only know how to translate strings from English so the source + * string should be in English. * Unlike regular t() translations, strings will be added to the source * tables only if this is marked as default data. * * @param string $name - * Configuration name. + * Name of the configuration location. * @param string $langcode * Language code to translate to. * @param string $source - * The source string. + * The source string, should be English. * @param string $context * The string context. * - * @return string|bool + * @return string|false * Translated string if there is a translation, FALSE if not. */ public function translateString($name, $langcode, $source, $context) { - if ($source) { - // Preload all translations for this configuration name and language. + if ($name && $langcode && $source && $context) { + // If translations for a language have not been loaded yet. if (!isset($this->translations[$name][$langcode])) { + // Preload all translations for this configuration name and language. $this->translations[$name][$langcode] = array(); foreach ($this->localeStorage->getTranslations(array('language' => $langcode, 'type' => 'configuration', 'name' => $name)) as $string){ $this->translations[$name][$langcode][$string->context][$string->source] = $string; } } - if (!isset($this->translations[$name][$langcode][$context][$source])) { + if (!isset($this->translations[$name][$langcode][$context][$source]) { + // There is no translation of the source string in this config location + // to this language for this context. if ($translation = $this->localeStorage->findTranslation(array('source' => $source, 'context' => $context, 'language' => $langcode))) { - // The translation was there but the location was missing. - // Convert to SourceString because it may not have translation. + // Look for a translation of the string. It might have one, but not + // be saved in this configuration location yet. + // If the string has a translation for this context to this language, + // save it in the configuration location so it can be looked up faster + // next time. $string = $this->localeStorage->createString((array) $translation) ->addLocation('configuration', $name) ->save(); } else { - // Add missing source string with the right location. + // No translation was found. Add the source to the configuration + // location so it can be translated, and the string is faster to look + // for next time. $translation = $this->localeStorage ->createString(array('source' => $source, 'context' => $context)) ->addLocation('configuration', $name) ->save(); } + + // Add an entry, either the translation found, or a blank string object + // to track the source string, to this configuration location, language, + // and context. $this->translations[$name][$langcode][$context][$source] = $translation; } + $translation = $this->translations[$name][$langcode][$context][$source]; - // Return the string only when the object is an actual translation. + // Return the string only when the string object had a translation. return $translation->isTranslation() ? $translation->getString() : FALSE; } return FALSE; } + } diff --git a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php index 5f184a8..928b323 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php @@ -2,7 +2,7 @@ /** * @file - * Contains Drupal\locale\LocaleTypedConfig. + * Contains \Drupal\locale\LocaleTypedConfig. */ namespace Drupal\locale; @@ -58,14 +58,14 @@ public function __construct(array $definition, $name, $langcode, \Drupal\locale\ } /** - * Get wrapped typed config object. + * Gets wrapped typed config object. */ public function getTypedConfig() { return $this->localeConfig->create($this->definition, $this->value); } /** - * Implements Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages(). + * Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages(). */ public function getTranslationLanguages($include_default = TRUE) { $languages = locale_translatable_language_list(); @@ -80,7 +80,7 @@ public function getTranslationLanguages($include_default = TRUE) { } /** - * Implements Drupal\Core\TypedData\TranslatableInterface::getTranslation(). + * Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslation(). */ public function getTranslation($langcode, $strict = TRUE) { $options = array( @@ -93,7 +93,7 @@ public function getTranslation($langcode, $strict = TRUE) { } /** - * Implements Drupal\Core\TypedData\TranslatableInterface::language(). + * Implements \Drupal\Core\TypedData\TranslatableInterface::language(). */ public function language() { return new Language(array('langcode' => $this->langcode)); @@ -107,7 +107,7 @@ public function language() { * @param string $to_langcode * Destination language code. * - * @return boolean + * @return bool * TRUE if this translator supports translations for these languages. */ protected function canTranslate($from_langcode, $to_langcode) { @@ -124,12 +124,12 @@ protected function canTranslate($from_langcode, $to_langcode) { * Typed configuration element. * @param array $options * Array with translation options that must contain the keys defined in - * LocaleTypedConfig::translateElement() + * \Drupal\locale\LocaleTypedConfig::translateElement() * * @return array * Configuration data translated to the requested language. */ - protected function getElementTranslation($element, array $options) { + protected function getElementTranslation(Element $element, array $options) { $translation = NULL; if ($element instanceof ArrayElement) { $translation = $this->getArrayTranslation($element, $options); @@ -152,7 +152,7 @@ protected function getElementTranslation($element, array $options) { * Typed configuration element. * @param array $options * Array with translation options that must contain the keys defined in - * LocaleTypedConfig::translateElement() + * \Drupal\locale\LocaleTypedConfig::translateElement() * * @return array * Configuration data translated to the requested language. @@ -201,7 +201,7 @@ protected function translateElement(\Drupal\Core\TypedData\TypedDataInterface $e } } } - // The element doesn't have a translation, if strict mode we drop it. + // The element does not have a translation. If strict mode we drop it. return empty($options['strict']); } diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php index eabdef0..eb5a1f3 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains Drupal\locale\Tests\LocaleConfigTranslationTest. + * Contains \Drupal\locale\Tests\LocaleConfigTranslationTest. */ namespace Drupal\locale\Tests; @@ -31,7 +31,7 @@ public static function getInfo() { ); } - function setUp() { + public function setUp() { parent::setUp(); // Add a default locale storage for all these tests. $this->storage = locale_storage(); @@ -41,7 +41,7 @@ function setUp() { * Tests basic configuration translation. */ function testConfigTranslation() { - // Add custom language + // Add custom language. $langcode = 'xx'; $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'translate interface', 'administer modules')); $this->drupalLogin($admin_user); diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 0b6f1b2..c830ece 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -547,17 +547,16 @@ function locale_translate_batch_import_save($context) { } /** - * Refresh translations after importing strings. + * Refreshs translations after importing strings. * * @param array $options * An array with options that can have the following elements: - * - 'refresh_configuration': Whether or not to refresh configuration strings - * after the import. Optional, defaults to FALSE. - * + * - 'refresh_configuration': (optional) Whether or not to refresh configuration + * strings after the import. Defaults to FALSE. * @param array $context * Contains a list of strings updated and information about the progress. */ -function locale_translate_batch_refresh($options, &$context) { +function locale_translate_batch_refresh(array $options, array &$context) { if (!isset($context['sandbox']['refresh'])) { $strings = $langcodes = array(); if (isset($context['results']['stats'])) { @@ -757,14 +756,14 @@ function locale_translate_delete_translation_files($projects = array(), $langcod } /** - * Build a locale batch to refresh configuration. + * Builds a locale batch to refresh configuration. * * @param array $options * An array with options that can have the following elements: - * - 'finish_feedback': Whether or not to give feedback to the user when the - * batch is finished. Optional, defaults to TRUE. + * - 'finish_feedback': (optional) Whether or not to give feedback to the user + * when the batch is finished. Defaults to TRUE. * @param array $langcodes - * Array of language codes. Defaults to all translatable languages. + * (optional) Array of language codes. Defaults to all translatable languages. * @param array $components * (optional) Array of component lists indexed by type. If not present or it * is an empty array, it will update all components. @@ -772,7 +771,7 @@ function locale_translate_delete_translation_files($projects = array(), $langcod * @return array * The batch definition. */ -function locale_config_batch_update_components($options, $langcodes = array(), $components = array()) { +function locale_config_batch_update_components(array $options, $langcodes = array(), $components = array()) { $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list()); if ($langcodes && $names = locale_config()->getComponentNames($components)) { return locale_config_batch_build($names, $langcodes, $options); @@ -787,14 +786,14 @@ function locale_config_batch_update_components($options, $langcodes = array(), $ * @param array $langcodes * List of language codes to refresh. * @param array $options - * An array with options that can have the following elements: + * (optional) An array with options that can have the following elements: * - 'finish_feedback': Whether or not to give feedback to the user when the - * batch is finished. Optional, defaults to TRUE. + * batch is finished. Defaults to TRUE. * * @return array * The batch definition. */ -function locale_config_batch_build($names, $langcodes, $options = array()) { +function locale_config_batch_build(array $names, array $langcodes, $options = array()) { $options += array('finish_feedback' => TRUE); $t = get_t(); foreach ($names as $name) { @@ -814,16 +813,16 @@ function locale_config_batch_build($names, $langcodes, $options = array()) { } /** - * Perform configuration translation refresh as a batch step. + * Performs configuration translation refresh as a batch step. * * @param array $name * Name of configuration object to update. * @param array $langcodes * (optional) Array of language codes to update. Defaults to all languages. - * @param $context + * @param array $context * Contains a list of files imported. */ -function locale_config_batch_refresh_name($name, $langcodes, &$context) { +function locale_config_batch_refresh_name(array $name, array $langcodes, array &$context) { if (!isset($context['result']['stats']['config'])) { $context['result']['stats']['config'] = 0; } @@ -834,14 +833,14 @@ function locale_config_batch_refresh_name($name, $langcodes, &$context) { } /** - * Finished callback of system page locale import batch. + * Finishes callback of system page locale import batch. * * @param bool $success * Information about the success of the batch import. * @param array $results * Information about the results of the batch import. */ -function locale_config_batch_finished($success, $results) { +function locale_config_batch_finished($success, array $results) { if ($success) { $configuration = isset($results['stats']['config']) ? $results['stats']['config'] : 0; if ($configuration) { @@ -862,10 +861,11 @@ function locale_config_batch_finished($success, $results) { * Array of names of configuration objects to update. * @param array $langcodes * (optional) Array of language codes to update. Defaults to all languages. + * * @return int * Number of configuration objects retranslated. */ -function locale_config_update_multiple($names, $langcodes = array()) { +function locale_config_update_multiple(array $names, $langcodes = array()) { $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list()); $count = 0; foreach ($names as $name) { diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 59ad5cd..9fd46d0 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -513,11 +513,11 @@ function locale_themes_disabled($themes) { * This function will start a batch to import translations for the added * components. * - * @param $components + * @param array $components * An array of arrays of component (theme and/or module) names to import * translations for, indexed by type. */ -function locale_system_update($components) { +function locale_system_update(array $components) { $components += array('module' => array(), 'theme' => array()); $list = array_merge($components['module'], $components['theme']); @@ -1076,7 +1076,7 @@ function _locale_refresh_translations($langcodes, $lids = array()) { } /** - * Refresh configuration after string translations have been updated. + * Refreshes configuration after string translations have been updated. * * The information that will be refreshed includes: * - JavaScript translations. @@ -1087,7 +1087,7 @@ function _locale_refresh_translations($langcodes, $lids = array()) { * @param array $lids * List of string identifiers that have been updated / created. */ -function _locale_refresh_configuration($langcodes, $lids) { +function _locale_refresh_configuration(array $langcodes, array $lids) { if ($lids && $langcodes && $names = locale_config()->getStringNames($lids)) { module_load_include('bulk.inc', 'locale'); locale_config_update_multiple($names, $langcodes); @@ -1361,7 +1361,7 @@ function _locale_rebuild_js($langcode = NULL) { * Use the locale config manager service for creating locale-wrapped typed * configuration objects. * - * @see Drupal\Core\TypedData\TypedDataManager::create() + * @see \Drupal\Core\TypedData\TypedDataManager::create() * * @return \Drupal\locale\LocaleConfigManager */