FileTranslation example

/** * @var \ReflectionMethod */
  protected $filePatternMethod;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->fileTranslation = new FileTranslation('filename', $this->container->get('file_system'));
    $method = new \ReflectionMethod('\Drupal\Core\StringTranslation\Translator\FileTranslation', 'getTranslationFilesPattern');
    $this->filePatternMethod = $method;
  }

  /** * @dataProvider providerValidTranslationFiles */
  public function testFilesPatternValid($langcode$filename) {
    $pattern = $this->filePatternMethod->invoke($this->fileTranslation, $langcode);
    $this->assertNotEmpty(preg_match($pattern$filename));
  }

  
    // we are looking for.     $expected_translation_files = [
      NULL => ['drupal-8.0.0-beta2.hu.po', 'drupal-8.0.0.de.po', 'drupal-8.0.x.fr-CA.po'],
      'de' => ['drupal-8.0.0.de.po'],
      'fr-CA' => ['drupal-8.0.x.fr-CA.po'],
      'hu' => ['drupal-8.0.0-beta2.hu.po'],
      'it' => [],
    ];

    // Hardcode the fixtures location as we don't yet know where it is.     // @todo Remove as part of https://www.drupal.org/node/2186491     $file_translation = new FileTranslation('core/tests/fixtures/files/translations', $this->container->get('file_system'));
    foreach ($expected_translation_files as $langcode => $files_expected) {
      $files_found = $file_translation->findTranslationFiles($langcode);
      $this->assertSameSize($files_expected$files_foundnew FormattableMarkup('@count installer languages found.', ['@count' => count($files_expected)]));
      foreach ($files_found as $file) {
        $this->assertContains($file->filename, $files_expectednew FormattableMarkup('@file found.', ['@file' => $file->filename]));
      }
    }
  }

  /** * Tests profile info caching in non-English languages. */
Home | Imprint | This part of the site doesn't use cookies.