Skip to content

Commit 77a467c

Browse files
authored
Fix #28: Fix saving strings with quote
1 parent 9544f66 commit 77a467c

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
## 1.0.1 under development
55

6-
- no changes in this release.
6+
- Bug #28: Fix saving strings with quote (darkdef)
77

88
## 1.0.0 May 13, 2021
99

10-
- Initial release.
10+
- Initial release.

src/MessageSource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ private function messagesToCode(array $messages): string
137137
}
138138

139139
$code .= "\n" . ' ';
140-
$code .= "'{$messageId}'";
140+
$code .= var_export($messageId, true);
141141
$code .= ' => ';
142-
$code .= "'{$messageData['message']}'";
142+
$code .= var_export($messageData['message'], true);
143143
$code .= ',';
144144
}
145145
$code .= "\n" . ']';

tests/MessageSourceTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ public function generateFailTranslationsData(): array
7979
];
8080
}
8181

82+
public function generateTranslationsDataWithQuotes(): array
83+
{
84+
return [
85+
[
86+
'app',
87+
'de',
88+
[
89+
'test\'.id1' => [
90+
'message' => 'app: \'Test 1\' on the (de)',
91+
'comment' => 'Translate \'wisely!',
92+
],
93+
'test.\'id2\'' => [
94+
'message' => 'app: Test 1\' on the (de)',
95+
'comment' => 'Translate \'wisely!',
96+
],
97+
'test."id3' => [
98+
'message' => 'app: "Test 2" on the (de)',
99+
],
100+
'test."id4"' => [
101+
'message' => 'app: Test 3" on the (de)',
102+
],
103+
],
104+
],
105+
];
106+
}
107+
82108
protected function tearDown(): void
83109
{
84110
$this->cleanFiles();
@@ -246,4 +272,18 @@ public function testReadMessages(string $category, string $locale, array $data):
246272
$messages = $messageSource->getMessages($category, $locale);
247273
$this->assertEquals($messages, $referenceMessages);
248274
}
275+
276+
/**
277+
* @dataProvider generateTranslationsDataWithQuotes
278+
*/
279+
public function testWriteQuotedString(string $category, string $locale, array $data): void
280+
{
281+
$this->path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'translate_tests' . uniqid();
282+
283+
$messageSource = new MessageSource($this->path);
284+
$messageSource->write($category, $locale, $data);
285+
foreach ($data as $id => $value) {
286+
$this->assertEquals($messageSource->getMessage($id, $category, $locale), $value['message']);
287+
}
288+
}
249289
}

0 commit comments

Comments
 (0)