importPoFile example

'access administration pages',
    ]);
    $this->drupalLogin($this->adminUser);
  }

  /** * Tests locale_get_plural() and \Drupal::translation()->formatPlural(). */
  public function testGetPluralFormat() {
    // Import some .po files with formulas to set up the environment.     // These will also add the languages to the system.     $this->importPoFile($this->getPoFileWithSimplePlural()[
      'langcode' => 'fr',
    ]);
    $this->importPoFile($this->getPoFileWithComplexPlural()[
      'langcode' => 'hr',
    ]);

    // Attempt to import some broken .po files as well to prove that these     // will not overwrite the proper plural formula imported above.     $this->importPoFile($this->getPoFileWithMissingPlural()[
      'langcode' => 'fr',
      'overwrite_options[not_customized]' => TRUE,
    ]);
    $this->config('locale.settings')
      ->set('translation.import_enabled', TRUE)
      ->set('translation.use_source', LOCALE_TRANSLATION_USE_SOURCE_LOCAL)
      ->save();
  }

  /** * Tests import of standalone .po files. */
  public function testStandalonePoFile() {
    // Try importing a .po file.     $this->importPoFile($this->getPoFile()[
      'langcode' => 'fr',
    ]);
    $this->config('locale.settings');
    // The import should automatically create the corresponding language.     $this->assertSession()->pageTextContains("The language French has been created.");

    // The import should have created 8 strings.     $this->assertSession()->pageTextContains("One translation file imported. 8 translations were added, 0 translations were updated and 0 translations were removed.");

    // This import should have saved plural forms to have 2 variants.     $locale_plurals = \Drupal::service('locale.plural.formula')->getNumberOfPlurals('fr');
    
Home | Imprint | This part of the site doesn't use cookies.