getStringTranslation example


      else {
        $config_importer = new ConfigImporter(
          $storage_comparer,
          $this->eventDispatcher,
          $this->configManager,
          $this->lock,
          $this->typedConfigManager,
          $this->moduleHandler,
          $this->moduleInstaller,
          $this->themeHandler,
          $this->getStringTranslation(),
          $this->moduleExtensionList,
          $this->themeExtensionList
        );

        try {
          $config_importer->validate();
          $form_state->set('config_importer', $config_importer);
        }
        catch (ConfigImporterException $e) {
          // There are validation errors.           $item_list = [
            
try {
        $this->moduleInstaller->install(array_keys($modules['install']));
        $this->messenger()
          ->addStatus($this->modulesEnabledConfirmationMessage($modules['install']));
      }
      catch (PreExistingConfigException $e) {
        $this->messenger()->addError($this->modulesFailToEnableMessage($modules$e));
        return;
      }
      catch (UnmetDependenciesException $e) {
        $this->messenger()->addError(
          $e->getTranslatedMessage($this->getStringTranslation()$modules['install'][$e->getExtension()])
        );
        return;
      }
    }
  }

}
return $this->arguments;
  }

  /** * Renders the object as a string. * * @return string * The translated string. */
  public function render() {
    if (!isset($this->translatedMarkup)) {
      $this->translatedMarkup = $this->getStringTranslation()->translateString($this);
    }

    // Handle any replacements.     if ($args = $this->getArguments()) {
      return $this->placeholderFormat($this->translatedMarkup, $args);
    }
    return $this->translatedMarkup;
  }

  /** * Magic __sleep() method to avoid serializing the string translator. */
      // submit, in which case the user has bigger problems.       try {
        // Install the given modules.         $this->moduleInstaller->install(array_keys($this->modules['install']));
      }
      catch (PreExistingConfigException $e) {
        $this->messenger()->addError($this->modulesFailToEnableMessage($this->modules, $e));
        return;
      }
      catch (UnmetDependenciesException $e) {
        $this->messenger()->addError(
          $e->getTranslatedMessage($this->getStringTranslation()$this->modules['install'][$e->getExtension()])
        );
        return;
      }

      // Unset the messenger to make sure that we'll get the service from the       // new container.       $this->messenger = NULL;
      $this->messenger()
        ->addStatus($this->modulesEnabledConfirmationMessage($this->modules['install']));
    }

    
return $plural;
  }

  /** * Renders the object as a string. * * @return string * The translated string. */
  public function render() {
    if (!$this->translatedString) {
      $this->translatedString = $this->getStringTranslation()->translateString($this);
    }
    if ($this->translatedString === '') {
      return '';
    }

    $arguments = $this->getArguments();
    $arguments['@count'] = $this->count;
    $translated_array = explode(PoItem::DELIMITER, $this->translatedString);

    if ($this->count == 1) {
      return $this->placeholderFormat($translated_array[0]$arguments);
    }

  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config_importer = new ConfigImporter(
      $form_state->get('storage_comparer'),
      $this->eventDispatcher,
      $this->configManager,
      $this->lock,
      $this->typedConfigManager,
      $this->moduleHandler,
      $this->moduleInstaller,
      $this->themeHandler,
      $this->getStringTranslation(),
      $this->moduleExtensionList,
      $this->themeExtensionList
    );
    if ($config_importer->alreadyImporting()) {
      $this->messenger()->addStatus($this->t('Another request may be synchronizing configuration already.'));
    }
    else {
      try {
        $sync_steps = $config_importer->initialize();
        $batch_builder = (new BatchBuilder())
          ->setTitle($this->t('Synchronizing configuration'))
          
return array_merge(...$this->translators);
  }

  /** * {@inheritdoc} */
  public function getStringTranslation($langcode$string$context) {
    if ($this->sortedTranslators === NULL) {
      $this->sortedTranslators = $this->sortTranslators();
    }
    foreach ($this->sortedTranslators as $translator) {
      $translation = $translator->getStringTranslation($langcode$string$context);
      if ($translation !== FALSE) {
        return $translation;
      }
    }
    // No translator got a translation.     return FALSE;
  }

  /** * {@inheritdoc} */
  

  public function getBundleLabel() {
    // If there is no bundle label defined, try to provide some sensible     // fallbacks.     if (!empty($this->bundle_label)) {
      return (string) $this->bundle_label;
    }
    elseif ($bundle_entity_type_id = $this->getBundleEntityType()) {
      return (string) \Drupal::entityTypeManager()->getDefinition($bundle_entity_type_id)->getLabel();
    }
    return (string) new TranslatableMarkup('@type_label bundle', ['@type_label' => $this->getLabel()][]$this->getStringTranslation());
  }

  /** * {@inheritdoc} */
  public function getBaseTable() {
    return $this->base_table;
  }

  /** * {@inheritdoc} */
$this->formatPlural(
            count($config_objects),
            'Unable to install @extension, %config_names already exists in active configuration.',
            'Unable to install @extension, %config_names already exist in active configuration.',
            [
              '%config_names' => implode(', ', $config_objects),
              '@extension' => $theme,
            ])
        );
      }
      catch (UnmetDependenciesException $e) {
        $this->messenger()->addError($e->getTranslatedMessage($this->getStringTranslation()$theme));
      }
      catch (MissingDependencyException $e) {
        $this->messenger()->addError($this->t('Unable to install @theme due to missing module dependencies.', ['@theme' => $theme]));
      }

      return $this->redirect('system.themes_page');
    }

    throw new AccessDeniedHttpException();
  }

  

  protected function t($string, array $args = [], array $options = []) {
    return new TranslatableMarkup($string$args$options$this->getStringTranslation());
  }

  /** * Formats a string containing a count of items. * * @see \Drupal\Core\StringTranslation\TranslationInterface::formatPlural() */
  protected function formatPlural($count$singular$plural, array $args = [], array $options = []) {
    return new PluralTranslatableMarkup($count$singular$plural$args$options$this->getStringTranslation());
  }

  

  protected function saveCustomizedTranslation($name$source$context$new_translation$langcode) {
    $locale_translation = $this->localeConfigManager->getStringTranslation($name$langcode$source$context);
    if (!empty($locale_translation)) {
      // If this code is triggered during installation never set the translation       // to the source string.       if (InstallerKernel::installationAttempted() && $source === $new_translation) {
        return;
      }
      // 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
$this->formatPlural(
          count($config_objects),
          'Unable to install @extension, %config_names already exists in active configuration.',
          'Unable to install @extension, %config_names already exist in active configuration.',
          [
            '%config_names' => implode(', ', $config_objects),
            '@extension' => $theme,
          ])
      );
    }
    catch (UnmetDependenciesException $e) {
      $this->messenger()->addError($e->getTranslatedMessage($this->getStringTranslation()$theme));
    }
    $form_state->setRedirectUrl($this->getCancelUrl());
  }

}

  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 {
      

  public function testGetStringTranslation() {
    $this->installSchema('locale', ['locales_location', 'locales_source', 'locales_target']);
    $this->installConfig(['locale_test']);

    $locale_config_manager = \Drupal::service('locale.config_manager');

    $language = ConfigurableLanguage::createFromLangcode('de');
    $language->save();

    $translation_before = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', '');
    $this->assertTrue($translation_before->isNew());
    $translation_before->setString('translation')->save();

    $translation_after = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', '');
    $this->assertFalse($translation_after->isNew());
    $translation_after->setString('updated_translation')->save();
  }

  /** * Tests getDefaultConfigLangcode(). */
  
Home | Imprint | This part of the site doesn't use cookies.