getTranslations example

'active' => $app->isActive(),
            'languages' => [],
            'type' => ExtensionStruct::EXTENSION_TYPE_APP,
            'isTheme' => \in_array($app->getName()$installedThemeNames, true),
            'configurable' => $app->isConfigurable(),
            'privacyPolicyExtension' => $app->getPrivacyPolicyExtensions(),
            'updatedAt' => $app->getUpdatedAt(),
            'allowDisable' => $app->getAllowDisable(),
            'domains' => $app->getAllowedHosts(),
        ];

        $appTranslations = $app->getTranslations();

        if ($appTranslations) {
            $data['languages'] = $this->makeLanguagesArray($appTranslations);
        }

        return $data;
    }

    /** * @param array<string, mixed> $data * * @return array<string, StoreCollection|mixed|null> */
static::assertNull($this->getStateMachines());

        $this->execute();

        $stateMachines = $this->getStateMachines();

        static::assertNotNull($stateMachines);
        static::assertCount(2, $stateMachines);
        static::assertArrayHasKey(OrderTransactionCaptureStates::STATE_MACHINE, $stateMachines);
        static::assertArrayHasKey(OrderTransactionCaptureRefundStates::STATE_MACHINE, $stateMachines);

        $translations = $this->getTranslations($stateMachines);

        static::assertIsArray($translations);
        static::assertCount(4, $translations);

        $states = $this->getStates($stateMachines);

        static::assertIsArray($states);
        static::assertCount(8, $states);

        $transitions = $this->getTransitions($stateMachines);

        


    public function testItSkipsTranslationsIfLanguageIsNotAvailable(): void
    {
        $bundle = $this->getThemeConfigWithLabels();
        $this->deleteLanguageForLocale('de-DE');

        $this->themeLifecycleService->refreshTheme($bundle$this->context);

        $theme = $this->getTheme($bundle);

        static::assertInstanceOf(ThemeTranslationCollection::class$theme->getTranslations());
        static::assertCount(1, $theme->getTranslations());
        static::assertEquals('en-GB', $theme->getTranslations()->first()?->getLanguage()?->getLocale()?->getCode());
        static::assertEquals([
            'fields.sw-image' => 'test label',
        ]$theme->getTranslations()->first()?->getLabels());
        static::assertEquals([
            'fields.sw-image' => 'test help',
        ]$theme->getTranslations()->first()?->getHelpTexts());
    }

    public function testItUsesEnglishTranslationsAsFallbackIfDefaultLanguageIsNotProvided(): void
    {
if (!empty($settings_locations)) {
      $source = $this->container->get('config.factory')->get($config_name)->get($key);
      $source_string = $this->localeStorage->findString(['source' => $source, 'type' => 'configuration']);
      $this->assertNotEmpty($source_string, "$config_name.$key should have a source string.");

      if (!empty($source_string)) {
        $conditions = [
          'lid' => $source_string->lid,
          'language' => $langcode,
        ];
        $translations = $this->localeStorage->getTranslations($conditions + ['translated' => TRUE]);
        return reset($translations);
      }
    }
    return FALSE;
  }

  /** * Sets site name and slogan for default language, helps in tests. * * @param string $site_name * The site name. * @param string $site_slogan * The site slogan. */

  public function translateString($name$langcode$source$context) {
    if ($source) {
      // If translations for a language have not been loaded yet.       if (!isset($this->translations[$name][$langcode])) {
        // Preload all translations for this configuration name and language.         $this->translations[$name][$langcode] = [];
        foreach ($this->localeStorage->getTranslations(['language' => $langcode, 'type' => 'configuration', 'name' => $name]) as $string) {
          $this->translations[$name][$langcode][$string->context][$string->source] = $string;
        }
      }
      if (!isset($this->translations[$name][$langcode][$context][$source])) {
        // There is no translation of the source string in this config location         // to this language for this context.         if ($translation = $this->localeStorage->findTranslation(['source' => $source, 'context' => $context, 'language' => $langcode])) {
          // Look for a translation of the string. It might have one, but not           // be saved in this configuration location yet.           // If the string has a translation for this context to this language,           // save it in the configuration location so it can be looked up faster


            if (isset($translationSet['plugin_form'])) {
                $this->addFormTranslation($form$translationSet['plugin_form']$locale);
                unset($translationSet['plugin_form']);
            }

            // Then the element translations             foreach ($translationSet as $targetName => $translationArray) {
                $isUpdate = false;
                $element = $form->getElement($targetName);
                foreach ($element->getTranslations() as $existingTranslation) {
                    // Check if translation for this locale already exists                     if ($existingTranslation->getLocale()->getLocale() != $locale->getLocale()) {
                        continue;
                    }

                    if (\array_key_exists('label', $translationArray)) {
                        $existingTranslation->setLabel($translationArray['label']);
                    }

                    if (\array_key_exists('description', $translationArray)) {
                        $existingTranslation->setDescription($translationArray['description']);
                    }
'not_customized' => FALSE,
      'customized' => FALSE,
    ];
    $overwrite_options = $this->options['overwrite_options'];
    $customized = $this->options['customized'];

    $context = $item->getContext();
    $source = $item->getSource();
    $translation = $item->getTranslation();

    // Look up the source string and any existing translation.     $strings = \Drupal::service('locale.storage')->getTranslations([
      'language' => $this->langcode,
      'source' => $source,
      'context' => $context,
    ]);
    $string = reset($strings);

    if (!empty($translation)) {
      // Skip this string unless it passes a check for dangerous code.       if (!locale_string_is_safe($translation)) {
        \Drupal::logger('locale')->error('Import of string "%string" was skipped because of disallowed or malformed HTML.', ['%string' => $translation]);
        $this->report['skips']++;
        
/** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('category.repository');

        $repository->create([$data]$context);

        $criteria = new Criteria([$id]);
        $criteria->addAssociation('translations');

        /** @var CategoryEntity $category */
        $category = $repository->search($criteria$context)->first();

        static::assertInstanceOf(CategoryTranslationCollection::class$category->getTranslations());
        /** @var CategoryTranslationEntity $enTranslation */
        $enTranslation = $category->getTranslations()->filterByLanguageId(Defaults::LANGUAGE_SYSTEM)->first();
        static::assertEquals('en translation', $enTranslation->getName());

        /** @var CategoryTranslationEntity $deTranslation */
        $deTranslation = $category->getTranslations()->filterByLanguageId($this->getDeDeLanguageId())->first();
        static::assertEquals('de übersetzung', $deTranslation->getName());
    }

    public function testTranslationValuesHavePriorityOverDefaultValueWithIds(): void
    {
        
break;

    }

    if (!empty($filter_values['string'])) {
      $options['filters']['source'] = $filter_values['string'];
      if ($options['translated']) {
        $options['filters']['translation'] = $filter_values['string'];
      }
    }

    return $this->localeStorage->getTranslations($conditions$options);
  }

  /** * Builds an array out of search criteria specified in request variables. * * @param bool $reset * If the list of values should be reset. * * @return array * The filter values. */
  
$emotionData['previewId'],
            $emotionData['previewSecret']
        );

        if (!$keepName) {
            unset($emotionData['name']);
        }

        $emotionData['active'] = false;

        $requiredPlugins = $this->getRequiredPlugins($emotionData['elements']);
        $emotionTranslations = $this->getTranslations($emotionData['elements']$emotionData['id']);

        unset($emotionData['id']);

        $emotionData['elements'] = $this->cleanupElements($emotionData['elements']);
        $data['emotionTranslations'] = json_encode($emotionTranslations);
        $data['requiredPlugins'] = $requiredPlugins;
        $data['presetData'] = json_encode($emotionData);

        return $data;
    }

    
'url' => $button->getUrl(),
                'icon' => $app->getIcon(),
            ];
        }$actionButtons->getElements()));
    }

    /** * @return array<string, string|null> */
    private function mapTranslatedLabels(ActionButtonEntity $button): array
    {
        $translations = $button->getTranslations();

        if ($translations === null) {
            return [];
        }

        $labels = [];
        foreach ($translations as $translation) {
            /** @var LanguageEntity $language */
            $language = $translation->getLanguage();

            /** @var LocaleEntity $locale */
            
foreach ($translations as $localeCode => $translationSet) {
            $locale = Shopware()->Models()->getRepository(Locale::class)->findOneBy(['locale' => $localeCode]);
            if (empty($locale)) {
                continue;
            }

            // First process the form translations             if (\array_key_exists('plugin_form', $translationSet)) {
                $isUpdate = false;
                $translationArray = $translationSet['plugin_form'];
                foreach ($form->getTranslations() as $existingTranslation) {
                    // Check if translation for this locale already exists                     if ($existingTranslation->getLocale()->getLocale() != $localeCode) {
                        continue;
                    }
                    if (\array_key_exists('label', $translationArray)) {
                        $existingTranslation->setLabel($translationArray['label']);
                    }
                    if (\array_key_exists('description', $translationArray)) {
                        $existingTranslation->setDescription($translationArray['description']);
                    }
                    $isUpdate = true;
                    

    public function update($id, array $data$locale = 'de_DE')
    {
        /** @var Preset|null $preset */
        $preset = $this->models->getRepository(Preset::class)->find($id);
        if (!$preset) {
            throw new NotFoundException(sprintf('Preset with id %s not found', $id));
        }

        $preset->getTranslations()->clear();
        $this->models->flush($preset);

        return $this->save($data$preset$locale);
    }

    /** * @param string $locale * * @throws ValidationException * * @return Preset */
'composerName' => $info->getName(),
                'path' => (new Filesystem())->makePathRelative($pluginPath$this->projectDir),
                'author' => $this->getAuthors($info),
                'copyright' => $extra['copyright'] ?? null,
                'license' => implode(', ', $license),
                'version' => $pluginVersion,
                'iconRaw' => $this->getPluginIconRaw($pluginPath . '/' . $pluginIconPath),
                'autoload' => $info->getAutoload(),
                'managedByComposer' => $pluginFromFileSystem->getManagedByComposer(),
            ];

            $pluginData['translations'] = $this->getTranslations($shopwareContext$extra);

            /** @var PluginEntity $currentPluginEntity */
            $currentPluginEntity = $installedPlugins->filterByProperty('baseClass', $baseClass)->first();
            if ($currentPluginEntity !== null) {
                $currentPluginId = $currentPluginEntity->getId();
                $pluginData['id'] = $currentPluginId;

                $currentPluginVersion = $currentPluginEntity->getVersion();
                if (!$currentPluginEntity->getInstalledAt()) {
                    $pluginData['version'] = $pluginVersion;
                    $pluginData['upgradeVersion'] = null;
                }
return [
            'source' => $this->sign($source$secret$context),
        ];
    }

    /** * @return array<string, string|null> */
    private function mapTranslatedLabels(AppEntity $app): array
    {
        $labels = [];
        $translations = $app->getTranslations();
        if ($translations === null) {
            return $labels;
        }

        foreach ($translations as $translation) {
            $code = $translation->getLanguage()?->getLocale()?->getCode();
            if ($code === null) {
                continue;
            }
            $labels[$code] = $translation->getLabel();
        }

        
Home | Imprint | This part of the site doesn't use cookies.