diff --git a/src/SpreadsheetParser.php b/src/SpreadsheetParser.php index e23330c..72a20a4 100644 --- a/src/SpreadsheetParser.php +++ b/src/SpreadsheetParser.php @@ -5,7 +5,6 @@ namespace Orkhanahmadov\SpreadsheetTranslations; use Illuminate\Contracts\Config\Repository; -use Illuminate\Support\Arr; use Illuminate\Support\Collection; use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; @@ -67,7 +66,7 @@ protected function parseRow(Row $row): void // get value from key column $translationKey = $this->parseTranslationKey($row->getColumnIterator()); - // ignore row if filename or identifier is empty + // ignore row if translation key is empty if (empty($translationKey)) { return; } @@ -77,11 +76,7 @@ protected function parseRow(Row $row): void /* * [ * 'en' => [ - * 'auth' => [ - * 'login' => [ - * 'title' => 'This is title translation for English', - * ], - * ] + * 'auth.login.title' => 'This is title translation for English', * ] * ] */ @@ -92,7 +87,7 @@ protected function parseRow(Row $row): void continue; } - Arr::set($this->translations[$locale], $translationKey, $value); + $this->translations[$locale][$translationKey] = $value; } } diff --git a/tests/SpreadsheetParserTest.php b/tests/SpreadsheetParserTest.php index ca0063f..3f8a460 100644 --- a/tests/SpreadsheetParserTest.php +++ b/tests/SpreadsheetParserTest.php @@ -26,8 +26,8 @@ public function testParsesListedLocaleTranslations(): void $this->assertSame( [ 'en' => [ - 'login' => ['welcome' => 'Welcome'], - 'dashboard' => ['statistics' => 'Statistics'], + 'login.welcome' => 'Welcome', + 'dashboard.statistics' => 'Statistics', ], ], $this->generator->parse()->getTranslations() @@ -45,12 +45,8 @@ public function testParsesMultiDimensionalTranslations(): void $this->assertSame( [ 'en' => [ - 'login' => [ - 'welcome' => 'Welcome', - 'form' => [ - 'first_name' => 'First name', - ], - ], + 'login.welcome' => 'Welcome', + 'login.form.first_name' => 'First name', ], ], $this->generator->parse()->getTranslations() @@ -67,9 +63,7 @@ public function testIgnoresIrrelevantColumns(): void $this->assertSame( [ 'en' => [ - 'login' => [ - 'welcome' => 'Welcome', - ], + 'login.welcome' => 'Welcome', ], ], $this->generator->parse()->getTranslations() @@ -89,22 +83,14 @@ public function testCanParseMultipleLocaleTranslations(): void $this->assertSame( [ 'en' => [ - 'login' => [ - 'welcome' => 'Welcome', - 'form' => [ - 'first_name' => 'First name', - ], - ], - 'dashboard' => ['statistics' => 'Statistics'], + 'login.welcome' => 'Welcome', + 'login.form.first_name' => 'First name', + 'dashboard.statistics' => 'Statistics', ], 'de' => [ - 'login' => [ - 'welcome' => 'Wilkommen', - 'form' => [ - 'first_name' => 'Vorname', - ], - ], - 'dashboard' => ['statistics' => 'Statistik'], + 'login.welcome' => 'Wilkommen', + 'login.form.first_name' => 'Vorname', + 'dashboard.statistics' => 'Statistik', ], ], $this->generator->parse()->getTranslations() @@ -126,17 +112,11 @@ public function testIgnoresEmptyTranslationFieldsInMultipleLocaleTranslations(): $this->assertSame( [ 'en' => [ - 'login' => [ - 'welcome' => 'Welcome', - ], - 'dashboard' => ['statistics' => 'Statistics'], + 'login.welcome' => 'Welcome', + 'dashboard.statistics' => 'Statistics', ], 'de' => [ - 'login' => [ - 'form' => [ - 'first_name' => 'Vorname', - ], - ], + 'login.form.first_name' => 'Vorname', ], ], $this->generator->parse()->getTranslations() @@ -154,9 +134,7 @@ public function testCanChooseDifferentRowsAsHeader(): void $this->assertSame( [ 'en' => [ - 'login' => [ - 'welcome' => 'Welcome', - ], + 'login.welcome' => 'Welcome', ], ], $this->generator->parse()->getTranslations() @@ -174,9 +152,7 @@ public function testCanChooseDifferentColumnForTranslationKey(): void $this->assertSame( [ 'en' => [ - 'login' => [ - 'welcome' => 'Welcome', - ], + 'login.welcome' => 'Welcome', ], ], $this->generator->parse()->getTranslations() @@ -195,9 +171,7 @@ public function testIgnoresRows(): void $this->assertSame( [ 'en' => [ - 'login' => [ - 'welcome' => 'Welcome', - ], + 'login.welcome' => 'Welcome', ], ], $this->generator->parse()->getTranslations() @@ -224,9 +198,7 @@ public function testParsesFromDifferentSheetByName(): void $this->assertSame( [ 'en' => [ - 'login' => [ - 'welcome' => 'Welcome', - ], + 'login.welcome' => 'Welcome', ], ], $this->generator->parse()->getTranslations()