setCustomized example


  protected function setUpTranslation($config_name$key$source$translation$langcode$is_active = FALSE) {
    // Create source and translation strings for the configuration value and add     // the configuration name as a location. This would be performed by     // locale_translate_batch_import() invoking     // LocaleConfigManager::updateConfigTranslations() normally.     $this->localeConfigManager->reset();
    $this->localeConfigManager
      ->getStringTranslation($config_name$langcode$source, '')
      ->setString($translation)
      ->setCustomized(FALSE)
      ->save();
    $this->configFactory->reset($config_name);
    $this->localeConfigManager->reset();
    $this->localeConfigManager->updateConfigTranslations([$config_name][$langcode]);

    if ($is_active) {
      $this->assertActiveConfig($config_name$key$translation$langcode);
    }
    else {
      $this->assertConfigOverride($config_name$key$translation$langcode);
    }
    
// Save this translation as custom if it was a new translation and not the       // same as the source. (The interface prefills translation values with the       // source). Or if there was an existing (non-empty) translation and the       // user changed it (even if it was changed back to the original value).       // Otherwise the translation file would be overwritten with the locale       // copy again later.       $existing_translation = $locale_translation->getString();
      if (($locale_translation->isNew() && $source != $new_translation) ||
        (!$locale_translation->isNew() && ((empty($existing_translation) && $source != $new_translation) || ((!empty($existing_translation) && $new_translation != $existing_translation))))) {
        $locale_translation
          ->setString($new_translation)
          ->setCustomized(TRUE)
          ->save();
      }
    }
  }

}
        $is_changed = TRUE;
      }
      elseif (!$existing_translation && !empty($new_translation_string)) {
        // Newly entered translation.         $is_changed = TRUE;
      }

      if ($is_changed) {
        // Only update or insert if we have a value to use.         $target = $existing_translation_objects[$lid] ?? $this->localeStorage->createTranslation(['lid' => $lid, 'language' => $langcode]);
        $target->setPlurals($new_translation['translations'])
          ->setCustomized()
          ->save();
        $updated[] = $target->getId();
      }
      if (empty($new_translation_string) && isset($existing_translation_objects[$lid])) {
        // Empty new translation entered: remove existing entry from database.         $existing_translation_objects[$lid]->delete();
        $updated[] = $lid;
      }
    }

    $this->messenger()->addStatus($this->t('The strings have been saved.'));

    
$this->assertEquals(\Drupal::VERSION, $string->version);

    // Create translation and find it by lid and source.     $langcode = 'es';
    $translation = $this->createTranslation($source$langcode);
    $this->assertEquals(LOCALE_NOT_CUSTOMIZED, $translation->customized);
    $string1 = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
    $this->assertEquals($translation->translation, $string1->translation);
    $string2 = $this->storage->findTranslation(['language' => $langcode, 'source' => $source->source, 'context' => $source->context]);
    $this->assertEquals($translation->translation, $string2->translation);
    $translation
      ->setCustomized()
      ->save();
    $translation = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
    $this->assertEquals(LOCALE_CUSTOMIZED, $translation->customized);

    // Delete translation.     $translation->delete();
    $deleted = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
    $this->assertNull($deleted->translation);

    // Create some translations and then delete string and all of its     // translations.
Home | Imprint | This part of the site doesn't use cookies.