setLanguage example

namespace Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\Hydrator;

use Shopware\Bundle\StoreFrontBundle\Struct\Locale;

class LocaleHydrator extends Hydrator
{
    public function hydrate($data)
    {
        $locale = new Locale();
        $locale->setId((int) $data['__locale_id']);
        $locale->setLocale($data['__locale_locale']);
        $locale->setLanguage($data['__locale_language']);
        $locale->setTerritory($data['__locale_territory']);

        return $locale;
    }
}
$this->assertStringContainsString('UNTRANSLATED', (string) $output);

    // Translate the separator.     ConfigurableLanguage::createFromLangcode('nl')->save();
    /** @var \Drupal\language\ConfigurableLanguageManagerInterface $language_manager */
    $language_manager = $this->container->get('language_manager');
    $language_manager->getLanguageConfigOverride('nl', 'core.entity_view_display.entity_test.entity_test.default')
      ->set('content.' . $this->fieldStorage->getName() . '.settings.separator', 'NL_TRANSLATED!')
      ->save();

    $this->container->get('language.config_factory_override')
      ->setLanguage(new Language(['id' => 'nl']));
    $this->container->get('cache_tags.invalidator')->invalidateTags($entity->getCacheTags());
    $display = EntityViewDisplay::collectRenderDisplay($entity, 'default');
    $build = $display->build($entity);
    $output = $this->container->get('renderer')->renderRoot($build);
    $this->assertStringContainsString('NL_TRANSLATED!', (string) $output);
  }

}


        $value = 'fo'.pack('C', 0x8F).'bar';
        $header = new UnstructuredHeader('Subject', $value);
        $header->setLanguage('en');
        $header->setCharset('iso-8859-1');
        $this->assertEquals('Subject: =?iso-8859-1*en?Q?fo=8Fbar?=', $header->toString());
    }

    public function testSetBody()
    {
        $header = new UnstructuredHeader('X-Test', '');
        $header->setBody('test');
        $this->assertEquals('test', $header->getValue());
    }

    


        $value = str_repeat('a', 20).pack('C', 0x8F).str_repeat('a', 10);
        $header = new ParameterizedHeader('Content-Disposition', 'attachment');
        $header->setCharset('iso-8859-1');
        $header->setValue('attachment');
        $header->setParameters(['filename' => $value]);
        $header->setLanguage($this->lang);
        $this->assertEquals(
            'attachment; filename*='.$header->getCharset()."'".$this->lang."'".
            str_repeat('a', 20).'%8F'.str_repeat('a', 10),
            $header->getBodyAsString()
        );
    }

    public function testMultipleEncodedParamLinesAreFormattedCorrectly()
    {
        /* -- RFC 2231, 4.1. Character set and language information may be combined with the parameter continuation mechanism. For example: Content-Type: application/x-stuff title*0*=us-ascii'en'This%20is%20even%20more%20 title*1*=%2A%2A%2Afun%2A%2A%2A%20 title*2="isn't it!" Note that: (1) Language and character set information only appear at the beginning of a given parameter value. (2) Continuations do not provide a facility for using more than one character set or language in the same parameter value. (3) A value presented using multiple continuations may contain a mixture of encoded and unencoded segments. (4) The first segment of a continuation MUST be encoded if language and character set information are given. (5) If the first segment of a continued parameter value is encoded the language and character set field delimiters MUST be present even when the fields are left blank. */
$edit = [
      'translation[config_names][config_translation_test.content][content][value]' => '<p><strong>Hello World</strong> - FR</p>',
      'translation[config_names][config_translation_test.content][animals][0]' => 'kitten - FR',
      'translation[config_names][config_translation_test.content][animals][1]' => 'llama - FR',
      'translation[config_names][config_translation_test.content][animals][2]' => 'elephant - FR',
    ];
    $this->drupalGet('admin/config/media/file-system/translate/fr/add');
    $this->submitForm($edit, 'Save translation');

    $this->container->get('language.config_factory_override')
      ->setLanguage(new Language(['id' => 'fr']));

    $expected = [
      'kitten - FR',
      'llama - FR',
      'elephant - FR',
    ];
    $actual = $config_factory
      ->get('config_translation_test.content')
      ->get('animals');
    $this->assertEquals($expected$actual);
  }

  
return $foundlang; //Returns false if language not found     }

    /** * Get the array of strings for the current language. * * @return array */
    public function getTranslations()
    {
        if (empty($this->language)) {
            $this->setLanguage(); // Set the default language.         }

        return $this->language;
    }

    /** * Create recipient headers. * * @param string $type * @param array $addr An array of recipients, * where each recipient is a 2-element indexed array with element 0 containing an address * and element 1 containing a name, like: * [['joe@example.com', 'Joe User'], ['zoe@example.com', 'Zoe User']] * * @return string */


  /** * Sets the configuration override language. * * @param \Drupal\Core\Language\LanguageInterface $language * The language to override configuration with. * * @return $this */
  public function setConfigOverrideLanguage(LanguageInterface $language = NULL) {
    $this->configFactoryOverride->setLanguage($language);
    return $this;
  }

  /** * {@inheritdoc} */
  public function getConfigOverrideLanguage() {
    return $this->configFactoryOverride->getLanguage();
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.