Skip to content

Commit

Permalink
fixed jscode extraction #121
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Aug 28, 2016
1 parent 46dff54 commit 18e329c
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Utils/JsFunctionsScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ public function getFunctions()
$buffer = '';
continue 3;
}

case ' ':
case '\t':
switch ($this->status()) {
case 'double-quote':
case 'simple-quote':
break;

default:
continue 3;
}
break;
}

switch ($this->status()) {
Expand Down
34 changes: 34 additions & 0 deletions tests/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,40 @@ public function testJsCode()
$this->runTestFormat('jscode/YamlDictionary', $countTranslations);
}

public function testJs2Code()
{
$translations = static::get('jscode2/input', 'JsCode');
$countTranslations = 3;
$countHeaders = 8;

$this->assertCount($countTranslations, $translations);
$this->assertCount($countHeaders, $translations->getHeaders());

$this->assertContent($translations, 'jscode2/Po');
$this->assertContent($translations, 'jscode2/Mo');
$this->assertContent($translations, 'jscode2/PhpArray');
$this->assertContent($translations, 'jscode2/Jed');
$this->assertContent($translations, 'jscode2/Json');
$this->assertContent($translations, 'jscode2/JsonDictionary');
$this->assertContent($translations, 'jscode2/Csv');
$this->assertContent($translations, 'jscode2/CsvDictionary');
$this->assertContent($translations, 'jscode2/Xliff');
$this->assertContent($translations, 'jscode2/Yaml');
$this->assertContent($translations, 'jscode2/YamlDictionary');

$this->runTestFormat('jscode2/Po', $countTranslations, $countHeaders);
$this->runTestFormat('jscode2/Mo', 0, $countHeaders);
$this->runTestFormat('jscode2/PhpArray', $countTranslations, $countHeaders);
$this->runTestFormat('jscode2/Jed', $countTranslations, 10);
$this->runTestFormat('jscode2/Xliff', $countTranslations, $countHeaders);
$this->runTestFormat('jscode2/Json', $countTranslations, $countHeaders);
$this->runTestFormat('jscode2/JsonDictionary', $countTranslations);
$this->runTestFormat('jscode2/Csv', $countTranslations, $countHeaders);
$this->runTestFormat('jscode2/CsvDictionary', $countTranslations);
$this->runTestFormat('jscode2/Yaml', $countTranslations, $countHeaders);
$this->runTestFormat('jscode2/YamlDictionary', $countTranslations);
}

public function testPhpCode()
{
$translations = static::get('phpcode/input', 'PhpCode');
Expand Down
12 changes: 12 additions & 0 deletions tests/assets/jscode2/Csv.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
,,"Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
Language:
Language-Team:
Last-Translator:
MIME-Version: 1.0
Project-Id-Version:
Report-Msgid-Bugs-To:
"
,"some message",
"some context","some message in a context",
,"%s message",
3 changes: 3 additions & 0 deletions tests/assets/jscode2/CsvDictionary.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"some message",
"some message in a context",
"%s message",
18 changes: 18 additions & 0 deletions tests/assets/jscode2/Jed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"messages": {
"": {
"domain": "messages",
"lang": "en",
"plural-forms": "nplurals=2; plural=(n != 1);"
},
"some message": [
""
],
"some context\\u0004some message in a context": [
""
],
"%s message": [
""
]
}
}
22 changes: 22 additions & 0 deletions tests/assets/jscode2/Json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"domain": null,
"plural-forms": null,
"messages": {
"": {
"": [
"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"
],
"some message": [
""
],
"%s message": [
""
]
},
"some context": {
"some message in a context": [
""
]
}
}
}
5 changes: 5 additions & 0 deletions tests/assets/jscode2/JsonDictionary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"some message": "",
"some message in a context": "",
"%s message": ""
}
Binary file added tests/assets/jscode2/Mo.mo
Binary file not shown.
37 changes: 37 additions & 0 deletions tests/assets/jscode2/PhpArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php return array (
'domain' => NULL,
'plural-forms' => NULL,
'messages' =>
array (
'' =>
array (
'' =>
array (
0 => 'Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
Language:
Language-Team:
Last-Translator:
MIME-Version: 1.0
Project-Id-Version:
Report-Msgid-Bugs-To:
',
),
'some message' =>
array (
0 => '',
),
'%s message' =>
array (
0 => '',
),
),
'some context' =>
array (
'some message in a context' =>
array (
0 => '',
),
),
),
);
24 changes: 24 additions & 0 deletions tests/assets/jscode2/Po.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
msgid ""
msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Language: \n"
"Language-Team: \n"
"Last-Translator: \n"
"MIME-Version: 1.0\n"
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"

#: ./tests/assets/jscode2/input.js:1
msgid "some message"
msgstr ""

#: ./tests/assets/jscode2/input.js:2
msgctxt "some context"
msgid "some message in a context"
msgstr ""

#: ./tests/assets/jscode2/input.js:3
msgid "%s message"
msgid_plural "%s messages"
msgstr[0] ""
45 changes: 45 additions & 0 deletions tests/assets/jscode2/Xliff.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="" trgLang="">
<file id=".">
<notes>
<note id="Content-Transfer-Encoding">8bit</note>
<note id="Content-Type">text/plain; charset=UTF-8</note>
<note id="Language"></note>
<note id="Language-Team"></note>
<note id="Last-Translator"></note>
<note id="MIME-Version">1.0</note>
<note id="Project-Id-Version"></note>
<note id="Report-Msgid-Bugs-To"></note>
</notes>
<unit id="df49b60423903e095b80d9b4a92eb065">
<notes>
<note category="context"></note>
<note category="reference">./tests/assets/jscode2/input.js:1</note>
</notes>
<segment>
<source>some message</source>
<target></target>
</segment>
</unit>
<unit id="79662f3fd7a86c2d14a8a9a707609a21">
<notes>
<note category="context">some context</note>
<note category="reference">./tests/assets/jscode2/input.js:2</note>
</notes>
<segment>
<source>some message in a context</source>
<target></target>
</segment>
</unit>
<unit id="ce1f2c3f5719b0353a6ef7805faf4a0d">
<notes>
<note category="context"></note>
<note category="reference">./tests/assets/jscode2/input.js:3</note>
</notes>
<segment>
<source>%s message</source>
<target></target>
</segment>
</unit>
</file>
</xliff>
10 changes: 10 additions & 0 deletions tests/assets/jscode2/Yaml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
domain: null
plural-forms: null
messages:
'':
'':
- "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"
'some message': ''
'%s message': ''
'some context':
'some message in a context': ''
3 changes: 3 additions & 0 deletions tests/assets/jscode2/YamlDictionary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'some message': ''
'some message in a context': ''
'%s message': ''
3 changes: 3 additions & 0 deletions tests/assets/jscode2/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gettext("some message");
pgettext("some context", "some message in a context");
ngettext("%s message", "%s messages", 2);

0 comments on commit 18e329c

Please sign in to comment.