Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
orkhanahmadov committed Mar 1, 2023
1 parent e9d69ee commit fe1380f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 54 deletions.
11 changes: 3 additions & 8 deletions src/SpreadsheetParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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',
* ]
* ]
*/
Expand All @@ -92,7 +87,7 @@ protected function parseRow(Row $row): void
continue;
}

Arr::set($this->translations[$locale], $translationKey, $value);
$this->translations[$locale][$translationKey] = $value;
}
}

Expand Down
64 changes: 18 additions & 46 deletions tests/SpreadsheetParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -67,9 +63,7 @@ public function testIgnoresIrrelevantColumns(): void
$this->assertSame(
[
'en' => [
'login' => [
'welcome' => 'Welcome',
],
'login.welcome' => 'Welcome',
],
],
$this->generator->parse()->getTranslations()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -154,9 +134,7 @@ public function testCanChooseDifferentRowsAsHeader(): void
$this->assertSame(
[
'en' => [
'login' => [
'welcome' => 'Welcome',
],
'login.welcome' => 'Welcome',
],
],
$this->generator->parse()->getTranslations()
Expand All @@ -174,9 +152,7 @@ public function testCanChooseDifferentColumnForTranslationKey(): void
$this->assertSame(
[
'en' => [
'login' => [
'welcome' => 'Welcome',
],
'login.welcome' => 'Welcome',
],
],
$this->generator->parse()->getTranslations()
Expand All @@ -195,9 +171,7 @@ public function testIgnoresRows(): void
$this->assertSame(
[
'en' => [
'login' => [
'welcome' => 'Welcome',
],
'login.welcome' => 'Welcome',
],
],
$this->generator->parse()->getTranslations()
Expand All @@ -224,9 +198,7 @@ public function testParsesFromDifferentSheetByName(): void
$this->assertSame(
[
'en' => [
'login' => [
'welcome' => 'Welcome',
],
'login.welcome' => 'Welcome',
],
],
$this->generator->parse()->getTranslations()
Expand Down

0 comments on commit fe1380f

Please sign in to comment.