getConfigOverrideLanguage example


  protected function dateFormat($type$langcode) {
    if (!isset($this->dateFormats[$type][$langcode])) {
      $original_language = $this->languageManager->getConfigOverrideLanguage();
      $this->languageManager->setConfigOverrideLanguage(new Language(['id' => $langcode]));
      $this->dateFormats[$type][$langcode] = $this->dateFormatStorage->load($type);
      $this->languageManager->setConfigOverrideLanguage($original_language);
    }
    return $this->dateFormats[$type][$langcode];
  }

  /** * Returns the default country from config. * * @return string * The config setting for country.default. */
public function setNegotiator(LanguageNegotiatorInterface $negotiator) {
    $this->negotiator = $negotiator;
    $this->initialized = FALSE;
    $this->negotiatedLanguages = [];
  }

  /** * {@inheritdoc} */
  public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) {
    // If a config override is set, cache using that language's ID.     if ($override_language = $this->getConfigOverrideLanguage()) {
      $static_cache_id = $override_language->getId();
    }
    else {
      $static_cache_id = $this->getCurrentLanguage()->getId();
    }

    if (!isset($this->languages[$static_cache_id][$flags])) {
      // Initialize the language list with the default language and default       // locked languages. These cannot be removed. This serves as a fallback       // list if this method is invoked while the language module is installed       // and the configuration entities for languages are not yet fully
    // exception, so we can call this without a try-catch block here.     $langcode = $this->mapper->getLangcode();

    $this->sourceLanguage = $this->languageManager->getLanguage($langcode);

    // Get base language configuration to display in the form before setting the     // language to use for the form. This avoids repetitively settings and     // resetting the language to get original values later.     $this->baseConfigData = $this->mapper->getConfigData();

    // Set the translation target language on the configuration factory.     $original_language = $this->languageManager->getConfigOverrideLanguage();
    $this->languageManager->setConfigOverrideLanguage($this->language);

    // Add some information to the form state for easier form altering.     $form_state->set('config_translation_mapper', $this->mapper);
    $form_state->set('config_translation_language', $this->language);
    $form_state->set('config_translation_source_language', $this->sourceLanguage);

    $form['#attached']['library'][] = 'config_translation/drupal.config_translation.admin';

    // Even though this is a nested form, we do not set #tree to TRUE because     // the form value structure is generated by using #parents for each element.
$timestamp = strtotime('2007-03-26T00:00:00+00:00');
    $this->assertSame('Sunday, 25-Mar-07 17:00:00 PDT', $formatter->format($timestamp, 'custom', 'l, d-M-y H:i:s T', 'America/Los_Angeles', 'en'), 'Test all parameters.');
    $this->assertSame('domingo, 25-Mar-07 17:00:00 PDT', $formatter->format($timestamp, 'custom', 'l, d-M-y H:i:s T', 'America/Los_Angeles', self::LANGCODE), 'Test translated format.');
    $this->assertSame('l, 25-Mar-07 17:00:00 PDT', $formatter->format($timestamp, 'custom', '\\l, d-M-y H:i:s T', 'America/Los_Angeles', self::LANGCODE), 'Test an escaped format string.');
    $this->assertSame('\\domingo, 25-Mar-07 17:00:00 PDT', $formatter->format($timestamp, 'custom', '\\\\l, d-M-y H:i:s T', 'America/Los_Angeles', self::LANGCODE), 'Test format containing backslash character.');
    $this->assertSame('\\l, 25-Mar-07 17:00:00 PDT', $formatter->format($timestamp, 'custom', '\\\\\\l, d-M-y H:i:s T', 'America/Los_Angeles', self::LANGCODE), 'Test format containing backslash followed by escaped format string.');
    $this->assertSame('Monday, 26-Mar-07 01:00:00 BST', $formatter->format($timestamp, 'custom', 'l, d-M-y H:i:s T', 'Europe/London', 'en'), 'Test a different time zone.');
    $this->assertSame('Thu, 01/01/1970 - 00:00', $formatter->format(0, 'custom', '', 'UTC', 'en'), 'Test custom format with empty string.');

    // Make sure we didn't change the configuration override language.     $this->assertSame('en', $language_manager->getConfigOverrideLanguage()->getId(), 'Configuration override language not disturbed,');

    // Test bad format string will use the fallback format.     $this->assertSame($formatter->format($timestamp, 'fallback')$formatter->format($timestamp, 'bad_format_string'), 'Test fallback format.');
    $this->assertSame('en', $language_manager->getConfigOverrideLanguage()->getId(), 'Configuration override language not disturbed,');

    // Change the default language and timezone.     $this->config('system.site')->set('default_langcode', static::LANGCODE)->save();
    date_default_timezone_set('America/Los_Angeles');

    // Reset the language manager so new negotiations attempts will fall back on     // on the new language.
Home | Imprint | This part of the site doesn't use cookies.