Skip to content

Commit 18e329c

Browse files
committed
fixed jscode extraction #121
1 parent 46dff54 commit 18e329c

14 files changed

Lines changed: 228 additions & 0 deletions

File tree

src/Utils/JsFunctionsScanner.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ public function getFunctions()
144144
$buffer = '';
145145
continue 3;
146146
}
147+
148+
case ' ':
149+
case '\t':
150+
switch ($this->status()) {
151+
case 'double-quote':
152+
case 'simple-quote':
153+
break;
154+
155+
default:
156+
continue 3;
157+
}
158+
break;
147159
}
148160

149161
switch ($this->status()) {

tests/AssetsTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,40 @@ public function testJsCode()
208208
$this->runTestFormat('jscode/YamlDictionary', $countTranslations);
209209
}
210210

211+
public function testJs2Code()
212+
{
213+
$translations = static::get('jscode2/input', 'JsCode');
214+
$countTranslations = 3;
215+
$countHeaders = 8;
216+
217+
$this->assertCount($countTranslations, $translations);
218+
$this->assertCount($countHeaders, $translations->getHeaders());
219+
220+
$this->assertContent($translations, 'jscode2/Po');
221+
$this->assertContent($translations, 'jscode2/Mo');
222+
$this->assertContent($translations, 'jscode2/PhpArray');
223+
$this->assertContent($translations, 'jscode2/Jed');
224+
$this->assertContent($translations, 'jscode2/Json');
225+
$this->assertContent($translations, 'jscode2/JsonDictionary');
226+
$this->assertContent($translations, 'jscode2/Csv');
227+
$this->assertContent($translations, 'jscode2/CsvDictionary');
228+
$this->assertContent($translations, 'jscode2/Xliff');
229+
$this->assertContent($translations, 'jscode2/Yaml');
230+
$this->assertContent($translations, 'jscode2/YamlDictionary');
231+
232+
$this->runTestFormat('jscode2/Po', $countTranslations, $countHeaders);
233+
$this->runTestFormat('jscode2/Mo', 0, $countHeaders);
234+
$this->runTestFormat('jscode2/PhpArray', $countTranslations, $countHeaders);
235+
$this->runTestFormat('jscode2/Jed', $countTranslations, 10);
236+
$this->runTestFormat('jscode2/Xliff', $countTranslations, $countHeaders);
237+
$this->runTestFormat('jscode2/Json', $countTranslations, $countHeaders);
238+
$this->runTestFormat('jscode2/JsonDictionary', $countTranslations);
239+
$this->runTestFormat('jscode2/Csv', $countTranslations, $countHeaders);
240+
$this->runTestFormat('jscode2/CsvDictionary', $countTranslations);
241+
$this->runTestFormat('jscode2/Yaml', $countTranslations, $countHeaders);
242+
$this->runTestFormat('jscode2/YamlDictionary', $countTranslations);
243+
}
244+
211245
public function testPhpCode()
212246
{
213247
$translations = static::get('phpcode/input', 'PhpCode');

tests/assets/jscode2/Csv.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
,,"Content-Transfer-Encoding: 8bit
2+
Content-Type: text/plain; charset=UTF-8
3+
Language:
4+
Language-Team:
5+
Last-Translator:
6+
MIME-Version: 1.0
7+
Project-Id-Version:
8+
Report-Msgid-Bugs-To:
9+
"
10+
,"some message",
11+
"some context","some message in a context",
12+
,"%s message",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"some message",
2+
"some message in a context",
3+
"%s message",

tests/assets/jscode2/Jed.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"messages": {
3+
"": {
4+
"domain": "messages",
5+
"lang": "en",
6+
"plural-forms": "nplurals=2; plural=(n != 1);"
7+
},
8+
"some message": [
9+
""
10+
],
11+
"some context\\u0004some message in a context": [
12+
""
13+
],
14+
"%s message": [
15+
""
16+
]
17+
}
18+
}

tests/assets/jscode2/Json.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"domain": null,
3+
"plural-forms": null,
4+
"messages": {
5+
"": {
6+
"": [
7+
"Content-Transfer-Encoding: 8bit\nContent-Type: text\/plain; charset=UTF-8\nLanguage: \nLanguage-Team: \nLast-Translator: \nMIME-Version: 1.0\nProject-Id-Version: \nReport-Msgid-Bugs-To: \n"
8+
],
9+
"some message": [
10+
""
11+
],
12+
"%s message": [
13+
""
14+
]
15+
},
16+
"some context": {
17+
"some message in a context": [
18+
""
19+
]
20+
}
21+
}
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"some message": "",
3+
"some message in a context": "",
4+
"%s message": ""
5+
}

tests/assets/jscode2/Mo.mo

225 Bytes
Binary file not shown.

tests/assets/jscode2/PhpArray.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php return array (
2+
'domain' => NULL,
3+
'plural-forms' => NULL,
4+
'messages' =>
5+
array (
6+
'' =>
7+
array (
8+
'' =>
9+
array (
10+
0 => 'Content-Transfer-Encoding: 8bit
11+
Content-Type: text/plain; charset=UTF-8
12+
Language:
13+
Language-Team:
14+
Last-Translator:
15+
MIME-Version: 1.0
16+
Project-Id-Version:
17+
Report-Msgid-Bugs-To:
18+
',
19+
),
20+
'some message' =>
21+
array (
22+
0 => '',
23+
),
24+
'%s message' =>
25+
array (
26+
0 => '',
27+
),
28+
),
29+
'some context' =>
30+
array (
31+
'some message in a context' =>
32+
array (
33+
0 => '',
34+
),
35+
),
36+
),
37+
);

tests/assets/jscode2/Po.po

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
msgid ""
2+
msgstr ""
3+
"Content-Transfer-Encoding: 8bit\n"
4+
"Content-Type: text/plain; charset=UTF-8\n"
5+
"Language: \n"
6+
"Language-Team: \n"
7+
"Last-Translator: \n"
8+
"MIME-Version: 1.0\n"
9+
"Project-Id-Version: \n"
10+
"Report-Msgid-Bugs-To: \n"
11+
12+
#: ./tests/assets/jscode2/input.js:1
13+
msgid "some message"
14+
msgstr ""
15+
16+
#: ./tests/assets/jscode2/input.js:2
17+
msgctxt "some context"
18+
msgid "some message in a context"
19+
msgstr ""
20+
21+
#: ./tests/assets/jscode2/input.js:3
22+
msgid "%s message"
23+
msgid_plural "%s messages"
24+
msgstr[0] ""

0 commit comments

Comments
 (0)