Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TranslationFiles.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class TranslationFiles extends \PHPUnit\Framework\TestCase
12 {
16  protected $csvParser;
17 
18  protected function setUp()
19  {
20  $this->csvParser = new \Magento\Framework\File\Csv(new File());
21  }
22 
26  public function getLocalePlacePath()
27  {
28  $pathToSource = BP;
29  $places = [];
31  foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $modulePath) {
32  $places[basename($modulePath)] = ['placePath' => $modulePath];
33  }
34  foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themePath) {
35  $placeName = basename(dirname(dirname($themePath))) . '_' . basename($themePath);
36  $places[$placeName] = ['placePath' => $themePath];
37  }
38  $places['lib_web'] = ['placePath' => "{$pathToSource}/lib/web"];
39  return $places;
40  }
41 
46  protected function getCsvFiles($modulePath)
47  {
48  $files = [];
49  foreach (glob("{$modulePath}/i18n/*.csv") as $file) {
50  $locale = str_replace('.csv', '', basename($file));
51  $files[$locale] = $file;
52  }
53  return $files;
54  }
55 
61  protected function comparePhrase($baseLocaleData, $localeData)
62  {
63  $missing = array_diff_key($baseLocaleData, $localeData);
64  $extra = array_diff_key($localeData, $baseLocaleData);
65 
66  $failures = [];
67  if (!empty($missing)) {
68  $failures['missing'] = array_keys($missing);
69  }
70  if (!empty($extra)) {
71  $failures['extra'] = array_keys($extra);
72  }
73  return $failures;
74  }
75 
81  protected function printMessage($failures, $message = '')
82  {
83  $message .= PHP_EOL;
84  foreach ($failures as $locale => $localeErrors) {
85  $message .= $locale . PHP_EOL;
86  foreach ($localeErrors as $typeError => $error) {
87  $message .= PHP_EOL . "##########" . PHP_EOL . ucfirst($typeError) . ':' . PHP_EOL;
88  foreach ($error as $phrase) {
89  $message .= '"' . $phrase . '","' . $phrase . '"' . PHP_EOL;
90  }
91  }
92  }
93  return $message;
94  }
95 }
$componentRegistrar
Definition: bootstrap.php:23
$message
const BP
Definition: autoload.php:14
foreach($appDirs as $dir) $files
if( $_orders &&count( $_orders))( 'Orders') ?></caption >< thead >< tr >< th scopeforeach( $_orders as $_order)(__( 'Order #')) ?>" class $extra
Definition: history.phtml:32