getStandardLanguageList example


    ];
    return [
      'un' => [
        ['language_list' => 'un'],
        $un_expected_output,
      ],
      'all' => [
        ['language_list' => 'all'],
        [
          'language' => [
            'textPartLanguage' => static::buildExpectedDynamicConfig(LanguageManager::getStandardLanguageList()),
          ],
        ],
      ],
      'default configuration' => [
        [],
        $un_expected_output,
      ],
    ];
  }

  /** * Builds the expected dynamic configuration output given a language list. * * @param array $language_list * The languages list from the language manager. * * @return array * The expected output of the dynamic plugin configuration. */
/** * Creates a configurable language object from a langcode. * * @param string $langcode * The language code to use to create the object. * * @return $this * * @see \Drupal\Core\Language\LanguageManager::getStandardLanguageList() */
  public static function createFromLangcode($langcode) {
    $standard_languages = LanguageManager::getStandardLanguageList();
    if (!isset($standard_languages[$langcode])) {
      // Drupal does not know about this language, so we set its values with the       // best guess. The user will be able to edit afterwards.       return static::create([
        'id' => $langcode,
        'label' => $langcode,
      ]);
    }
    else {
      // A known predefined language, details will be filled in properly.       return static::create([
        
/** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state$install_state = NULL) {
    if (count($install_state['translations']) > 1) {
      $files = $install_state['translations'];
    }
    else {
      $files = [];
    }
    $standard_languages = LanguageManager::getStandardLanguageList();
    $select_options = [];
    $browser_options = [];

    $form['#title'] = 'Choose language';

    // Build a select list with language names in native language for the user     // to choose from. And build a list of available languages for the browser     // to select the language default from.     // Select lists based on all standard languages.     foreach ($standard_languages as $langcode => $language_names) {
      $select_options[$langcode] = $language_names[1];
      
public function testRfc2822DateFormat() {
    $language_manager = $this->createMock(LanguageManager::class);
    $language_manager->expects($this->any())
      ->method('getCurrentLanguage')
      ->willReturn(new Language(['id' => $this->randomMachineName(2)]));
    $container = new ContainerBuilder();
    $container->set('language_manager', $language_manager);
    \Drupal::setContainer($container);

    $time = '2019-02-02T13:30';
    $timezone = new \DateTimeZone('Europe/Berlin');
    $langcodes = array_keys(LanguageManager::getStandardLanguageList());
    $langcodes[] = NULL;
    foreach ($langcodes as $langcode) {
      $datetime = new DrupalDateTime($time$timezone['langcode' => $langcode]);
      // Check that RFC2822 format date is returned regardless of langcode.       $this->assertEquals('Sat, 02 Feb 2019 13:30:00 +0100', $datetime->format('r'));
    }
  }

}
/** * Installer step: Select language. */
  protected function setUpLanguage() {
    // Place a custom local translation in the translations directory.     mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
    touch($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.xoxo.po');

    // Check that all predefined languages show up with their native names.     $this->visitInstaller();
    foreach (LanguageManager::getStandardLanguageList() as $langcode => $names) {
      $this->assertSession()->optionExists('edit-langcode', $langcode);
      $this->assertSession()->responseContains('>' . $names[1] . '<');
    }

    // Check that our custom one shows up with the file name indicated language.     $this->assertSession()->optionExists('edit-langcode', 'xoxo');
    $this->assertSession()->responseContains('>xoxo<');

    parent::setUpLanguage();
  }

  
/** * {@inheritdoc} */
  protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
    $langcode = $form_state->getValue('predefined_langcode');
    if ($langcode == 'custom') {
      $langcode = $form_state->getValue('langcode');
      $label = $form_state->getValue('label');
      $direction = $form_state->getValue('direction');
    }
    else {
      $standard_languages = LanguageManager::getStandardLanguageList();
      $label = $standard_languages[$langcode][0];
      $direction = $standard_languages[$langcode][2] ?? ConfigurableLanguage::DIRECTION_LTR;
    }
    $entity->set('id', $langcode);
    $entity->set('label', $label);
    $entity->set('direction', $direction);
    // There is no weight on the edit form. Fetch all configurable languages     // ordered by weight and set the new language to be placed after them.     $languages = \Drupal::languageManager()->getLanguages(ConfigurableLanguage::STATE_CONFIGURABLE);
    $last_language = end($languages);
    $entity->setWeight($last_language->getWeight() + 1);
  }


  /** * Tests that an RFC2822 formatted date always returns an English string. * * @see http://www.faqs.org/rfcs/rfc2822.html * * @covers ::format */
  public function testRfc2822DateFormat(): void {
    $timestamp = 1549110600;
    $langcodes = array_keys(LanguageManager::getStandardLanguageList());
    $langcodes[] = NULL;
    foreach ($langcodes as $langcode) {
      $formatted_date = $this->dateFormatter->format($timestamp, 'custom', 'r', 'Europe/Berlin', $langcode);
      // Check that RFC2822 format date is returned regardless of langcode.       $this->assertSame('Sat, 02 Feb 2019 13:30:00 +0100', $formatted_date);
    }
  }

  /** * Creates a UNIX timestamp given a date and time string. * * @param string $dateTimeString * The formatted date and time string. The format is year-month-day * hour:minute:seconds (e.g. 2013-12-11 10:09:08). * * @return int * The UNIX timestamp. */

  public function __construct(array $values = []) {
    // Set all the provided properties for the language.     foreach ($values as $key => $value) {
      if (property_exists($this$key)) {
        $this->{$key} = $value;
      }
    }
    // If some values were not set, set sane defaults of a predefined language.     if (!isset($values['name']) || !isset($values['direction'])) {
      $predefined = LanguageManager::getStandardLanguageList();
      if (isset($predefined[$this->id])) {
        if (!isset($values['name'])) {
          $this->name = $predefined[$this->id][0];
        }
        if (!isset($values['direction']) && isset($predefined[$this->id][2])) {
          $this->direction = $predefined[$this->id][2];
        }
      }
    }
  }

  

class Language extends CKEditor5PluginDefault implements CKEditor5PluginConfigurableInterface {

  use CKEditor5PluginConfigurableTrait;

  /** * {@inheritdoc} */
  public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor): array {
    $predefined_languages = $this->configuration['language_list'] === 'all' ?
      LanguageManager::getStandardLanguageList() :
      LanguageManager::getUnitedNationsLanguageList();

    // Generate the language_list setting as expected by the CKEditor Language     // plugin, but key the values by the full language name so that we can sort     // them later on.     $language_list = [];
    foreach ($predefined_languages as $langcode => $language) {
      $english_name = $language[0];
      $direction = empty($language[2]) ? NULL : $language[2];
      $language_list[$english_name] = [
        'title' => $english_name,
        
$assert_session->assertWaitOnAjaxRequest();

    // Confirm there are no longer any warnings.     $assert_session->waitForElementRemoved('css', '[data-drupal-messages] [role="alert"]');

    // Test for "United Nations' official languages" option.     $languages = LanguageManager::getUnitedNationsLanguageList();
    $this->languageOfPartsPluginTestHelper($page$assert_session$languages, "un");

    // Test for "All 95 languages" option.     $this->drupalGet('admin/config/content/formats/manage/ckeditor5');
    $languages = LanguageManager::getStandardLanguageList();
    $this->languageOfPartsPluginTestHelper($page$assert_session$languages, "all");
  }

  /** * Validate the available languages on the basis of selected language option. */
  public function languageOfPartsPluginTestHelper($page$assert_session$predefined_languages$option) {
    $this->assertNotEmpty($assert_session->waitForElement('css', 'a[href^="#edit-editor-settings-plugins-ckeditor5-language"]'));

    // Set correct value.     $vertical_tab_link = $page->find('xpath', "//ul[contains(@class, 'vertical-tabs__menu')]/li/a[starts-with(@href, '#edit-editor-settings-plugins-ckeditor5-language')]");
    
public function read($name) {
    if ($this->requiredInstallStorage->exists($name)) {
      return $this->requiredInstallStorage->read($name);
    }
    elseif ($this->optionalInstallStorage->exists($name)) {
      return $this->optionalInstallStorage->read($name);
    }
    elseif (str_starts_with($name, 'language.entity.')) {
      // Simulate default languages as if they were shipped as default       // configuration.       $langcode = str_replace('language.entity.', '', $name);
      $predefined_languages = $this->languageManager->getStandardLanguageList();
      if (isset($predefined_languages[$langcode])) {
        $data = $this->configStorage->read($name);
        $data['label'] = $predefined_languages[$langcode][0];
        return $data;
      }
    }
  }

  /** * Return the list of configuration in install storage and current languages. * * @return array * List of configuration in install storage and current languages. */

  public function getLanguageConfigOverrideStorage($langcode) {
    return $this->configFactoryOverride->getStorage($langcode);
  }

  /** * {@inheritdoc} */
  public function getStandardLanguageListWithoutConfigured() {
    $languages = $this->getLanguages();
    $predefined = $this->getStandardLanguageList();
    foreach ($predefined as $key => $value) {
      if (isset($languages[$key])) {
        unset($predefined[$key]);
        continue;
      }
      $predefined[$key] = new TranslatableMarkup($value[0]);
    }
    natcasesort($predefined);
    return $predefined;
  }

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