getLanguageConfigOverride example

    $this->drupalGet('admin/modules');
    $this->submitForm(['modules[config_install_fail_test][enable]' => TRUE], 'Install');
    $this->submitForm([], 'Continue');
    $this->assertSession()->responseContains('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');

    // Test that collection configuration clashes during a module install are     // reported correctly.     \Drupal::service('module_installer')->install(['language']);
    $this->rebuildContainer();
    ConfigurableLanguage::createFromLangcode('fr')->save();
    \Drupal::languageManager()
      ->getLanguageConfigOverride('fr', 'config_test.dynamic.dotted.default')
      ->set('label', 'Je suis Charlie')
      ->save();

    $this->drupalGet('admin/modules');
    $this->submitForm(['modules[config_install_fail_test][enable]' => TRUE], 'Install');
    $this->assertSession()->responseContains('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default</em> already exist in active configuration.');

    // Test installing a theme through the UI that has existing configuration.     // This relies on the fact the config_test has been installed and created     // the config_test.dynamic.dotted.default configuration and the translation     // override created still exists.
$overridden_sync = $sync->createCollection('language.fr');
    $overridden_sync->write('system.site', ['name' => 'French site name']);

    // Before we start the import, the change to the site name should not be     // present. This action also primes the cache in the config factory so that     // we can test whether the cached data is correctly updated.     $config = $this->config('system.site');
    $this->assertNotEquals('English site name', $config->getRawData()['name']);

    // Before the import is started the site name should not yet be overridden.     $this->assertFalse($config->hasOverrides());
    $override = $language_manager->getLanguageConfigOverride('fr', 'system.site');
    $this->assertTrue($override->isNew());

    // Start the import of the new configuration.     $this->configImporter->reset()->import();

    // Verify the new site name in the default language.     $config = $this->config('system.site')->getRawData();
    $this->assertEquals('English site name', $config['name']);

    // Verify the overridden site name.     $override = $language_manager->getLanguageConfigOverride('fr', 'system.site');
    
'd6_field_instance_option_translation',
    ]);
  }

  /** * Tests migration of file variables to file.settings.yml. */
  public function testFieldInstanceOptionTranslation() {
    $language_manager = $this->container->get('language_manager');

    /** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_float_single_checkbox');
    $option_translation = ['on_label' => 'fr - 1.234'];
    $this->assertSame($option_translation$config_translation->get('settings'));

    $config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.field.node.story.field_test_float_single_checkbox');
    $option_translation = ['on_label' => 'zu - 1.234'];
    $this->assertSame($option_translation$config_translation->get('settings'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_text_single_checkbox');
    $option_translation = [
      'off_label' => 'fr - Hello',
      'on_label' => 'fr - Goodbye',
    ];
/** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_values = $form_state->getValue(['translation', 'config_names']);

    foreach ($form_values as $name => $value) {
      $schema = $this->typedConfigManager->get($name);

      // Set configuration values based on form submission and source values.       $base_config = $this->configFactory()->getEditable($name);
      $config_translation = $this->languageManager->getLanguageConfigOverride($this->language->getId()$name);

      $element = $this->createFormElement($schema);
      $element->setConfig($base_config$config_translation$value);

      // If no overrides, delete language specific configuration file.       $saved_config = $config_translation->get();
      if (empty($saved_config)) {
        $config_translation->delete();
        $this->messenger()->addStatus($this->t('@language translation was not added. To add a translation, you must modify the configuration.', ['@language' => $this->language->getName()]));
      }
      else {
        

  protected function saveLanguageOverride($config_name$key$value$langcode) {
    $translation_override = $this->languageManager
      ->getLanguageConfigOverride($langcode$config_name);
    $translation_override
      ->set($key$value)
      ->save();
    $this->configFactory->reset($config_name);

    $this->assertConfigOverride($config_name$key$value$langcode);
  }

  /** * Saves translation data from locale module. * * This will invoke LocaleConfigSubscriber through the event dispatcher. To * make sure the configuration was persisted correctly, the configuration * value is checked. Because LocaleConfigSubscriber temporarily disables the * override state of the configuration factory we check that the correct value * is restored afterwards. * * @param string $config_name * The configuration name. * @param string $key * The configuration key. * @param string $source * The source string. * @param string $translation * The translation string to save. * @param string $langcode * The language code. * @param bool $is_active * Whether the update will affect the active configuration. */
'd7_menu',
      'd7_menu_translation',
    ]);
  }

  /** * Tests migration of menu translations. */
  public function testMenuTranslation() {
    $language_manager = \Drupal::service('language_manager');

    $config_translation = $language_manager->getLanguageConfigOverride('is', 'system.menu.main');
    $this->assertSame('is - Main menu', $config_translation->get('label'));
    $this->assertSame('is - Main menu description', $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'system.menu.main');
    $this->assertSame('fr - Main menu', $config_translation->get('label'));
    $this->assertSame('fr - Main menu description', $config_translation->get('description'));

    // Translate and localize menu.     $config_translation = $language_manager->getLanguageConfigOverride('fr', 'system.menu.menu-test-menu');
    $this->assertSame('fr - Test menu description', $config_translation->get('description'));

    
$this->mapper = $mapper;
    $this->language = $language;
    return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    foreach ($this->mapper->getConfigNames() as $name) {
      $this->languageManager->getLanguageConfigOverride($this->language->getId()$name)->delete();
    }

    // Flush all persistent caches.     $this->moduleHandler->invokeAll('cache_flush');
    foreach (Cache::getBins() as $cache_backend) {
      $cache_backend->deleteAll();
    }

    $this->messenger()->addStatus($this->t('@language translation of %label was deleted', ['%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()]));

    $form_state->setRedirectUrl($this->getCancelUrl());
  }
// The view should now use the new plural configuration.     $this->drupalGet('sl/numeric-test');
    $this->assertSession()->responseContains('<span class="field-content">0 time3</span>');
    $this->assertSession()->responseContains('<span class="field-content">1 time0</span>');
    $this->assertSession()->responseContains('<span class="field-content">2 time1</span>');
    $this->assertSession()->responseContains('<span class="field-content">3 time2</span>');
    $this->assertSession()->responseContains('<span class="field-content">4 time2</span>');
    $this->assertSession()->responseContains('<span class="field-content">42 time3</span>');

    // Add an English configuration translation with English plurals.     $english = \Drupal::languageManager()->getLanguageConfigOverride('en', 'views.view.numeric_test');
    $english->set('display.default.display_options.fields.count.format_plural_string', '1 time' . PoItem::DELIMITER . '@count times')->save();

    // The view displayed in English should use the English translation.     $this->drupalGet('numeric-test');
    $this->assertSession()->responseContains('<span class="field-content">0 times</span>');
    $this->assertSession()->responseContains('<span class="field-content">1 time</span>');
    $this->assertSession()->responseContains('<span class="field-content">2 times</span>');
    $this->assertSession()->responseContains('<span class="field-content">3 times</span>');
    $this->assertSession()->responseContains('<span class="field-content">4 times</span>');
    $this->assertSession()->responseContains('<span class="field-content">42 times</span>');
  }

  

  public function testUserProfileFields() {
    $this->executeMigrations([
      'language',
      'user_profile_field',
      'user_profile_field_instance',
      'd6_user_profile_field_instance_translation',
    ]);
    $language_manager = $this->container->get('language_manager');

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_really_really_love_mig');
    $this->assertSame("J'aime les migrations", $config_translation->get('label'));
    $this->assertSame("Si vous cochez cette case, vous aimez les migrations.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_color');
    $this->assertSame('fr - Favorite color', $config_translation->get('label'));
    $this->assertSame('Inscrivez votre couleur préférée', $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_biography');
    $this->assertSame('fr - Biography', $config_translation->get('label'));
    $this->assertSame('fr - Tell people a little bit about yourself', $config_translation->get('description'));

    

  protected function saveTranslationOverride($name$langcode, array $data) {
    $this->isUpdatingFromLocale = TRUE;
    $this->languageManager->getLanguageConfigOverride($langcode$name)->setData($data)->save();
    $this->isUpdatingFromLocale = FALSE;
  }

  /** * Saves translated configuration data. * * @param string $name * Configuration object name. * @param array $data * Configuration data to be saved with translations merged in. */
  

  }

  /** * Tests the Drupal 6 field to Drupal 8 migration. */
  public function testFieldOptionTranslation() {
    $language_manager = $this->container->get('language_manager');

    // Test a select list with allowed values of key only.     /** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_test_integer_selectlist');
    $allowed_values = [
      1 => [
        'label' => 'fr - 2341',
      ],
      3 => [
        'label' => 'fr - 4123',
      ],
    ];
    $this->assertSame($allowed_values$config_translation->get('settings.allowed_values'));

    $config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.storage.node.field_test_integer_selectlist');
    
'rename' => [],
    ];
    $this->assertEquals($expected_changelist_spanish_collection$comparer->getChangelist(NULL, 'language.es'));

    // Ensure that menu blocks have been created correctly.     $this->assertSession()->responseNotContains('This block is broken or missing.');
    $this->assertSession()->linkExists('Add content');

    // Ensure that the Spanish translation of anonymous is the one from     // configuration and not the PO file.     // cspell:disable-next-line     $this->assertSame('Anónimo', \Drupal::languageManager()->getLanguageConfigOverride('es', 'user.settings')->get('anonymous'));

    /** @var \Drupal\locale\StringStorageInterface $locale_storage */
    $locale_storage = \Drupal::service('locale.storage');
    // If configuration contains a translation that is not in the po file then     // _install_config_locale_overrides_process_batch() will create a customized     // translation.     $translation = $locale_storage->findTranslation(['source' => 'Anonymous', 'language' => 'es']);
    $this->assertSame('Anónimo', $translation->getString());
    $this->assertTrue((bool) $translation->customized, "A customized translation has been created for Anonymous");

    // If configuration contains a translation that is in the po file then
$this->drupalGet('admin/config/regional/translate');
      $this->submitForm($edit, 'Filter');
      $this->assertSession()->pageTextContains($sample . ' de');
    }

    /** @var \Drupal\language\ConfigurableLanguageManager $language_manager */
    $language_manager = \Drupal::languageManager();

    // Installed in German, configuration should be in German. No German or     // English overrides should be present.     $config = \Drupal::config('user.settings');
    $override_de = $language_manager->getLanguageConfigOverride('de', 'user.settings');
    $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
    $this->assertEquals('Anonymous de', $config->get('anonymous'));
    $this->assertEquals('de', $config->get('langcode'));
    $this->assertTrue($override_de->isNew());
    $this->assertTrue($override_en->isNew());

    // Assert that adding English makes the English override available.     $edit = ['predefined_langcode' => 'en'];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add language');
    $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
    
$this->drupalGet('admin/config/regional/translate');
    $this->submitForm($search, 'Filter');
    $textarea = $this->assertSession()->elementExists('xpath', '//textarea');
    $lid = $textarea->getAttribute('name');
    $edit = [
      $lid => $message,
    ];
    $this->drupalGet('admin/config/regional/translate');
    $this->submitForm($edit, 'Save translations');

    // Get translation and check we've only got the message.     $translation = \Drupal::languageManager()->getLanguageConfigOverride($this->langcode, 'system.maintenance')->get();
    $this->assertCount(1, $translation, 'Got the right number of properties after translation.');
    $this->assertEquals($message$translation['message']);

    // Check default medium date format exists and create a translation for it.     $string = $this->storage->findString(['source' => 'D, m/d/Y - H:i', 'context' => 'PHP date format', 'type' => 'configuration']);
    $this->assertNotEmpty($string, 'Configuration date formats have been created upon installation.');

    // Translate using the UI so configuration is refreshed.     $search = [
      'string' => $string->source,
      'langcode' => $this->langcode,
      
'd6_profile_field_option_translation',
    ]);
  }

  /** * Tests the Drupal 6 field option translation. */
  public function testFieldOptionTranslation() {
    $language_manager = $this->container->get('language_manager');

    /** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.user.profile_count_trees');
    $allowed_values = [
      0 => [
        'label' => 'fr - 10',
      ],
      1 => [
        'label' => 'fr - 20',
      ],
      2 => [
        'label' => 'fr - 50',
      ],
      3 => [
        
Home | Imprint | This part of the site doesn't use cookies.