Verified Commit dc9a4c53 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3422915 by magaki, karanpagare, joachim, alexpott, Keshav Patel,...

Issue #3422915 by magaki, karanpagare, joachim, alexpott, Keshav Patel, smustgrave, Aguillet: Deprecate Drupal\locale\Locale and its one method
parent 7cfb8bbd
Loading
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -6,12 +6,11 @@
 */

use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Url;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\file\FileInterface;
use Drupal\locale\Gettext;
use Drupal\locale\Locale;

/**
 * Prepare a batch to import all translations.
@@ -328,7 +327,8 @@ function locale_translate_batch_refresh(&$context) {
  }
  elseif ($name = array_shift($context['sandbox']['refresh']['names'])) {
    // Refresh all languages for one object at a time.
    $count = Locale::config()->updateConfigTranslations([$name], $context['sandbox']['refresh']['languages']);
    $count = \Drupal::service('locale.config_manager')
      ->updateConfigTranslations([$name], $context['sandbox']['refresh']['languages']);
    $context['results']['stats']['config'] += $count;
    // Inherit finished information from the "parent" string lookup step so
    // visual display of status will make sense.
@@ -344,7 +344,8 @@ function locale_translate_batch_refresh(&$context) {
    // Clear cache and force refresh of JavaScript translations.
    _locale_refresh_translations($context['sandbox']['refresh']['languages'], $next);
    // Check whether we need to refresh configuration objects.
    if ($names = Locale::config()->getStringNames($next)) {
    if ($names = \Drupal::service('locale.config_manager')
      ->getStringNames($next)) {
      $context['sandbox']['refresh']['names_finished'] = $context['finished'];
      $context['sandbox']['refresh']['names'] = $names;
    }
@@ -547,7 +548,7 @@ function locale_translate_delete_translation_files(array $projects = [], array $
 */
function locale_config_batch_update_components(array $options, array $langcodes = [], array $components = [], bool $update_default_config_langcodes = FALSE) {
  $langcodes = $langcodes ? $langcodes : array_keys(\Drupal::languageManager()->getLanguages());
  if ($langcodes && $names = Locale::config()->getComponentNames($components)) {
  if ($langcodes && $names = \Drupal::service('locale.config_manager')->getComponentNames($components)) {
    // If the component list is empty we need to ensure that all configuration
    // in the default collection is using the site's default langcode.
    return locale_config_batch_build($names, $langcodes, $options, $update_default_config_langcodes);
@@ -612,7 +613,7 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
 *   The batch context.
 */
function locale_config_batch_set_config_langcodes(&$context) {
  Locale::config()->updateDefaultConfigLangcodes();
  \Drupal::service('locale.config_manager')->updateDefaultConfigLangcodes();
  $context['finished'] = 1;
  $context['message'] = t('Updated default configuration to %langcode', ['%langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId()]);
}
@@ -635,7 +636,8 @@ function locale_config_batch_refresh_name(array $names, array $langcodes, &$cont
  if (!isset($context['results']['stats']['config'])) {
    $context['results']['stats']['config'] = 0;
  }
  $context['results']['stats']['config'] += Locale::config()->updateConfigTranslations($names, $langcodes);
  $context['results']['stats']['config'] += \Drupal::service('locale.config_manager')
    ->updateConfigTranslations($names, $langcodes);
  foreach ($names as $name) {
    $context['results']['names'][] = $name;
  }
+5 −5
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\ConfigurableLanguageInterface;
use Drupal\Component\Utility\Crypt;
use Drupal\locale\Locale;
use Drupal\locale\LocaleEvent;
use Drupal\locale\LocaleEvents;

@@ -238,7 +237,7 @@ function locale_configurable_language_delete(ConfigurableLanguageInterface $lang
  locale_translate_delete_translation_files([], [$language->id()]);

  // Remove translated configuration objects.
  Locale::config()->deleteLanguageTranslations($language->id());
  \Drupal::service('locale.config_manager')->deleteLanguageTranslations($language->id());

  // Changing the language settings impacts the interface:
  _locale_invalidate_js($language->id());
@@ -367,7 +366,7 @@ function locale_cron() {
 * Updates default configuration when new modules or themes are installed.
 */
function locale_system_set_config_langcodes() {
  Locale::config()->updateDefaultConfigLangcodes();
  \Drupal::service('locale.config_manager')->updateDefaultConfigLangcodes();
}

/**
@@ -1053,8 +1052,9 @@ function _locale_refresh_translations($langcodes, $lids = []) {
 *   List of string identifiers that have been updated / created.
 */
function _locale_refresh_configuration(array $langcodes, array $lids) {
  if ($lids && $langcodes && $names = Locale::config()->getStringNames($lids)) {
    Locale::config()->updateConfigTranslations($names, $langcodes);
  $locale_config_manager = \Drupal::service('locale.config_manager');
  if ($lids && $langcodes && $names = $locale_config_manager->getStringNames($lids)) {
    $locale_config_manager->updateConfigTranslations($names, $langcodes);
  }
}

+14 −2
Original line number Diff line number Diff line
@@ -2,8 +2,15 @@

namespace Drupal\locale;

@trigger_error('The ' . __NAMESPACE__ . '\Locale is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3437110', E_USER_DEPRECATED);

/**
 * Static service container wrapper for locale.
 *
 * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0.
 *   There is no replacement.
 *
 * @see https://www.drupal.org/node/3437110
 */
class Locale {

@@ -13,11 +20,16 @@ class Locale {
   * Use the locale config manager service for creating locale-wrapped typed
   * configuration objects.
   *
   * @see \Drupal\Core\TypedData\TypedDataManager::create()
   *
   * @return \Drupal\locale\LocaleConfigManager
   *   The locale configuration manager.
   *
   * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0.
   *   Use \Drupal::service('locale.config_manager') instead.
   *
   * @see https://www.drupal.org/node/3437110
   */
  public static function config() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal::service(\'locale.config_manager\') instead. See https://www.drupal.org/node/3437110', E_USER_DEPRECATED);
    return \Drupal::service('locale.config_manager');
  }

+2 −3
Original line number Diff line number Diff line
@@ -4,9 +4,8 @@

namespace Drupal\Tests\locale\Functional;

use Drupal\locale\Locale;
use Drupal\Tests\BrowserTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;

/**
 * Tests translation update's effects on configuration translations.
@@ -233,7 +232,7 @@ public function testLocaleRemovalAndConfigOverrideDelete() {
    $string = $locale_storage->findString(['source' => 'Locale can translate']);
    \Drupal::service('locale.storage')->delete($string);
    // Force a rebuild of config translations.
    $count = Locale::config()->updateConfigTranslations(['locale_test_translate.settings'], ['af']);
    $count = \Drupal::service('locale.config_manager')->updateConfigTranslations(['locale_test_translate.settings'], ['af']);
    $this->assertEquals(1, $count, 'Correct count of updated translations');

    $override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'locale_test_translate.settings');
+4 −4
Original line number Diff line number Diff line
@@ -4,11 +4,10 @@

namespace Drupal\Tests\locale\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\locale\Locale;
use Drupal\locale\StringInterface;
use Drupal\locale\TranslationString;
use Drupal\KernelTests\KernelTestBase;

/**
 * Tests that shipped configuration translations are updated correctly.
@@ -69,8 +68,9 @@ protected function setUp(): void {
    // @see locale_system_update()
    locale_system_set_config_langcodes();
    $langcodes = array_keys(\Drupal::languageManager()->getLanguages());
    $names = Locale::config()->getComponentNames();
    Locale::config()->updateConfigTranslations($names, $langcodes);
    $locale_config_manager = \Drupal::service('locale.config_manager');
    $names = $locale_config_manager->getComponentNames();
    $locale_config_manager->updateConfigTranslations($names, $langcodes);

    $this->configFactory = $this->container->get('config.factory');
    $this->stringStorage = $this->container->get('locale.storage');
Loading