setTranslation example



            $isoCode = $this->getShop()->getId();
            $translationReader = $this->getTranslationReader();

            if ($fallback = $this->getShop()->getFallback()) {
                $translation = $translationReader->readWithFallback($isoCode$fallback->getId(), 'config_mails', $mailModel->getId());
            } else {
                $translation = $translationReader->read($isoCode, 'config_mails', $mailModel->getId());
            }

            $mailModel->setTranslation($translation);
        } else {
            $defaultContext = [
                'sConfig' => $config,
            ];
        }

        $context = $eventManager->filter(
            'TemplateMail_CreateMail_MailContext',
            $context,
            [
                'mailModel' => $mailModel,
            ]
\Drupal::service('locale.plural.formula')->setPluralFormula($langcode$nplurals$formula);
      }
    }
  }

  /** * {@inheritdoc} */
  public function writeItem(PoItem $item) {
    if ($item->isPlural()) {
      $item->setSource(implode(PoItem::DELIMITER, $item->getSource()));
      $item->setTranslation(implode(PoItem::DELIMITER, $item->getTranslation()));
    }
    $this->importString($item);
  }

  /** * {@inheritdoc} */
  public function writeItems(PoReaderInterface $reader$count = -1) {
    $forever = $count == -1;
    while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
      $this->writeItem($item);
    }

  public function setFromArray(array $values = []) {
    if (isset($values['context'])) {
      $this->setContext($values['context']);
    }
    if (isset($values['source'])) {
      $this->setSource($values['source']);
    }
    if (isset($values['translation'])) {
      $this->setTranslation($values['translation']);
    }
    if (isset($values['comment'])) {
      $this->setComment($values['comment']);
    }
    if (isset($this->source) && str_contains($this->source, self::DELIMITER)) {
      $this->setSource(explode(self::DELIMITER, $this->source));
      $this->setTranslation(explode(self::DELIMITER, $this->translation ?? ''));
      $this->setPlural(count($this->source) > 1);
    }
  }

  
'userId' => $userId,
                        'status' => ($mode === 'allow' ? 'accepted' : 'rejected'),
                    ],
                ]
            );

            return;
        }

        $translationReader = $this->container->get(Shopware_Components_Translation::class);
        $translation = $translationReader->read($customer['languageId'], 'config_mails', $mailModel->getId());
        $mailModel->setTranslation($translation);

        $mailData = [
            'content' => nl2br($mailModel->getContent()) ?: '',
            'fromMail' => $mailModel->getFromMail() ?: '{config name=mail}',
            'fromName' => $mailModel->getFromName() ?: '{config name=shopName}',
            'subject' => $mailModel->getSubject(),
            'toMail' => $customer['email'],
            'userId' => $userId,
            'status' => ($mode === 'allow' ? 'accepted' : 'rejected'),
        ];
        $this->View()->assign(['success' => true, 'data' => $mailData]);
    }

  public function __construct() {
    $this->items = [];
  }

  /** * {@inheritdoc} */
  public function writeItem(PoItem $item) {
    if (is_array($item->getSource())) {
      $item->setSource(implode(PoItem::DELIMITER, $item->getSource()));
      $item->setTranslation(implode(PoItem::DELIMITER, $item->getTranslation()));
    }
    $context = $item->getContext();
    $this->items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
  }

  /** * {@inheritdoc} */
  public function writeItems(PoReaderInterface $reader$count = -1) {
    $forever = $count == -1;
    while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
      
$questionHelper = $this->getHelper('question');

        foreach ($missingSnippetsCollection->getIterator() as $missingSnippetStruct) {
            $question = sprintf(
                "<info>Available translation: '%s' in locale '%s'.</info>\n<question>Please enter translation for locale '%s':</question>",
                $missingSnippetStruct->getAvailableTranslation(),
                $missingSnippetStruct->getAvailableISO(),
                $missingSnippetStruct->getMissingForISO()
            );

            $missingSnippetStruct->setTranslation($questionHelper->ask($input$outputnew Question($question)) ?? '');
        }

        $this->snippetFixer->fix($missingSnippetsCollection);

        return self::SUCCESS;
    }

    private function hydrateMissingSnippets(array $missingSnippetsArray): MissingSnippetCollection
    {
        $missingSnippetsCollection = new MissingSnippetCollection();
        foreach ($missingSnippetsArray as $locale => $missingSnippets) {
            


    if (is_array($value['msgstr'])) {
      // Sort plural variants by their form index.       ksort($value['msgstr']);
      $plural = TRUE;
    }

    $item = new PoItem();
    $item->setContext($value['msgctxt'] ?? '');
    $item->setSource($value['msgid']);
    $item->setTranslation($value['msgstr']);
    $item->setPlural($plural);
    $item->setComment($comments);
    $item->setLangcode($this->langcode);

    $this->lastItem = $item;

    $this->context = 'COMMENT';
  }

  /** * Parses a string in quotes. * * @param $string * A string specified with enclosing quotes. * * @return bool|string * The string parsed from inside the quotes. False when the syntax is * invalid. */
Home | Imprint | This part of the site doesn't use cookies.