Skip to content

Commit 6597645

Browse files
committed
added Jed tests, and other bugfixes #90
1 parent b2d8d4f commit 6597645

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

src/Extractors/Jed.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public static function fromString($string, Translations $translations = null, $f
1818
$translations = new Translations();
1919
}
2020

21-
$content = json_decode($string);
21+
$content = json_decode($string, true);
2222

23-
return PhpArray::handleArray($content, $translations);
23+
PhpArray::handleArray($content, $translations);
24+
25+
return $translations;
2426
}
2527

2628
/**

src/Extractors/PhpArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function fromString($string, Translations $translations = null, $f
4747
*/
4848
public static function handleArray(array $content, Translations $translations)
4949
{
50-
$content = $content['messages'];
50+
$content = current($content);
5151

5252
$translations_info = isset($content['']) ? $content[''] : null;
5353
unset($content['']);

tests/JedGeneratorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
class JedGeneratorTest extends PHPUnit_Framework_TestCase
4+
{
5+
public function testOne()
6+
{
7+
//Extract translations
8+
$translations = Gettext\Extractors\Po::fromFile(__DIR__.'/files/po.po');
9+
10+
11+
$jed = $translations->toJedString();
12+
$expect = file_get_contents(__DIR__.'/files/jed.json');
13+
14+
$this->assertEquals(json_decode($jed), json_decode($expect));
15+
16+
$jed2 = Gettext\Extractors\Jed::fromString($expect);
17+
18+
$this->assertEquals($translations->count(), $jed2->count());
19+
}
20+
}

tests/files/jed.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"testingdomain":{
3+
"":{
4+
"domain":"testingdomain",
5+
"lang":"bs",
6+
"plural-forms":"nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);"
7+
},
8+
"Ensure this value has at least %(limit_value)d character (it has %sd).":[
9+
"Ensure this value has at least %(limit_value)d characters (it has %sd).",
10+
""
11+
],
12+
"Ensure this value has at most %(limit_value)d character (it has %sd).":[
13+
"Ensure this value has at most %(limit_value)d characters (it has %sd).",
14+
""
15+
],
16+
"%ss must be unique for %ss %ss.":[
17+
"",
18+
"%ss mora da bude jedinstven za %ss %ss."
19+
],
20+
"and":[
21+
"",
22+
"i"
23+
],
24+
"Value %sr is not a valid choice.":[
25+
"",
26+
""
27+
],
28+
"This field cannot be null.":[
29+
"",
30+
"Ovo polje ne mo\u017ee ostati prazno."
31+
],
32+
"This field cannot be blank.":[
33+
"",
34+
"Ovo polje ne mo\u017ee biti prazno."
35+
],
36+
"Field of type: %ss":[
37+
"",
38+
"Polje tipa: %ss"
39+
],
40+
"Integer":[
41+
"",
42+
"Cijeo broj"
43+
],
44+
"{test1}":[
45+
"",
46+
"test1\n<div>\n test2\n<\/div>\ntest3"
47+
],
48+
"{test2}":[
49+
"",
50+
"test1\n<div>\n test2\n<\/div>\ntest3"
51+
]
52+
}
53+
}

0 commit comments

Comments
 (0)