Skip to content

Commit fe1380f

Browse files
committed
WIP
1 parent e9d69ee commit fe1380f

File tree

2 files changed

+21
-54
lines changed

2 files changed

+21
-54
lines changed

src/SpreadsheetParser.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Orkhanahmadov\SpreadsheetTranslations;
66

77
use Illuminate\Contracts\Config\Repository;
8-
use Illuminate\Support\Arr;
98
use Illuminate\Support\Collection;
109
use PhpOffice\PhpSpreadsheet\Exception;
1110
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
@@ -67,7 +66,7 @@ protected function parseRow(Row $row): void
6766
// get value from key column
6867
$translationKey = $this->parseTranslationKey($row->getColumnIterator());
6968

70-
// ignore row if filename or identifier is empty
69+
// ignore row if translation key is empty
7170
if (empty($translationKey)) {
7271
return;
7372
}
@@ -77,11 +76,7 @@ protected function parseRow(Row $row): void
7776
/*
7877
* [
7978
* 'en' => [
80-
* 'auth' => [
81-
* 'login' => [
82-
* 'title' => 'This is title translation for English',
83-
* ],
84-
* ]
79+
* 'auth.login.title' => 'This is title translation for English',
8580
* ]
8681
* ]
8782
*/
@@ -92,7 +87,7 @@ protected function parseRow(Row $row): void
9287
continue;
9388
}
9489

95-
Arr::set($this->translations[$locale], $translationKey, $value);
90+
$this->translations[$locale][$translationKey] = $value;
9691
}
9792
}
9893

tests/SpreadsheetParserTest.php

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function testParsesListedLocaleTranslations(): void
2626
$this->assertSame(
2727
[
2828
'en' => [
29-
'login' => ['welcome' => 'Welcome'],
30-
'dashboard' => ['statistics' => 'Statistics'],
29+
'login.welcome' => 'Welcome',
30+
'dashboard.statistics' => 'Statistics',
3131
],
3232
],
3333
$this->generator->parse()->getTranslations()
@@ -45,12 +45,8 @@ public function testParsesMultiDimensionalTranslations(): void
4545
$this->assertSame(
4646
[
4747
'en' => [
48-
'login' => [
49-
'welcome' => 'Welcome',
50-
'form' => [
51-
'first_name' => 'First name',
52-
],
53-
],
48+
'login.welcome' => 'Welcome',
49+
'login.form.first_name' => 'First name',
5450
],
5551
],
5652
$this->generator->parse()->getTranslations()
@@ -67,9 +63,7 @@ public function testIgnoresIrrelevantColumns(): void
6763
$this->assertSame(
6864
[
6965
'en' => [
70-
'login' => [
71-
'welcome' => 'Welcome',
72-
],
66+
'login.welcome' => 'Welcome',
7367
],
7468
],
7569
$this->generator->parse()->getTranslations()
@@ -89,22 +83,14 @@ public function testCanParseMultipleLocaleTranslations(): void
8983
$this->assertSame(
9084
[
9185
'en' => [
92-
'login' => [
93-
'welcome' => 'Welcome',
94-
'form' => [
95-
'first_name' => 'First name',
96-
],
97-
],
98-
'dashboard' => ['statistics' => 'Statistics'],
86+
'login.welcome' => 'Welcome',
87+
'login.form.first_name' => 'First name',
88+
'dashboard.statistics' => 'Statistics',
9989
],
10090
'de' => [
101-
'login' => [
102-
'welcome' => 'Wilkommen',
103-
'form' => [
104-
'first_name' => 'Vorname',
105-
],
106-
],
107-
'dashboard' => ['statistics' => 'Statistik'],
91+
'login.welcome' => 'Wilkommen',
92+
'login.form.first_name' => 'Vorname',
93+
'dashboard.statistics' => 'Statistik',
10894
],
10995
],
11096
$this->generator->parse()->getTranslations()
@@ -126,17 +112,11 @@ public function testIgnoresEmptyTranslationFieldsInMultipleLocaleTranslations():
126112
$this->assertSame(
127113
[
128114
'en' => [
129-
'login' => [
130-
'welcome' => 'Welcome',
131-
],
132-
'dashboard' => ['statistics' => 'Statistics'],
115+
'login.welcome' => 'Welcome',
116+
'dashboard.statistics' => 'Statistics',
133117
],
134118
'de' => [
135-
'login' => [
136-
'form' => [
137-
'first_name' => 'Vorname',
138-
],
139-
],
119+
'login.form.first_name' => 'Vorname',
140120
],
141121
],
142122
$this->generator->parse()->getTranslations()
@@ -154,9 +134,7 @@ public function testCanChooseDifferentRowsAsHeader(): void
154134
$this->assertSame(
155135
[
156136
'en' => [
157-
'login' => [
158-
'welcome' => 'Welcome',
159-
],
137+
'login.welcome' => 'Welcome',
160138
],
161139
],
162140
$this->generator->parse()->getTranslations()
@@ -174,9 +152,7 @@ public function testCanChooseDifferentColumnForTranslationKey(): void
174152
$this->assertSame(
175153
[
176154
'en' => [
177-
'login' => [
178-
'welcome' => 'Welcome',
179-
],
155+
'login.welcome' => 'Welcome',
180156
],
181157
],
182158
$this->generator->parse()->getTranslations()
@@ -195,9 +171,7 @@ public function testIgnoresRows(): void
195171
$this->assertSame(
196172
[
197173
'en' => [
198-
'login' => [
199-
'welcome' => 'Welcome',
200-
],
174+
'login.welcome' => 'Welcome',
201175
],
202176
],
203177
$this->generator->parse()->getTranslations()
@@ -224,9 +198,7 @@ public function testParsesFromDifferentSheetByName(): void
224198
$this->assertSame(
225199
[
226200
'en' => [
227-
'login' => [
228-
'welcome' => 'Welcome',
229-
],
201+
'login.welcome' => 'Welcome',
230202
],
231203
],
232204
$this->generator->parse()->getTranslations()

0 commit comments

Comments
 (0)