Skip to content

Commit 868fd11

Browse files
committed
changed Jed extractor to be compatible with Jed generator #90
1 parent 36b69aa commit 868fd11

2 files changed

Lines changed: 45 additions & 12 deletions

File tree

src/Extractors/Jed.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,26 @@ public static function fromString($string, Translations $translations = null, $f
2222

2323
return PhpArray::handleArray($content, $translations);
2424
}
25+
26+
/**
27+
* Extract and insert a new translation
28+
*
29+
* @param Translations $translations
30+
* @param string $key
31+
* @param string $message
32+
*/
33+
protected static function insertTranslation(Translations $translations, $key, $message)
34+
{
35+
$context_glue = '\u0004';
36+
$key = explode($context_glue, $key);
37+
38+
$context = isset($key[1]) ? array_shift($key) : '';
39+
$original = array_shift($key);
40+
$translation = array_shift($message);
41+
$plural_translation = array_shift($message);
42+
43+
$entry = $translations->insert($context, $original);
44+
$entry->setTranslation($translation);
45+
$entry->setPluralTranslation($plural_translation);
46+
}
2547
}

src/Extractors/PhpArray.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,31 @@ public static function handleArray(array $content, Translations $translations)
5656
$translations->setDomain($translations_info['domain']);
5757
}
5858

59-
$context_glue = '\u0004';
60-
6159
foreach ($content as $key => $message) {
62-
$key = explode($context_glue, $key);
60+
static::insertTranslation($translations, $key, $message);
61+
}
62+
}
6363

64-
$context = isset($key[1]) ? array_shift($key) : '';
65-
$original = array_shift($key);
66-
$plural = array_shift($message);
67-
$translation = array_shift($message);
68-
$plural_translation = array_shift($message);
64+
/**
65+
* Extract and insert a new translation
66+
*
67+
* @param Translations $translations
68+
* @param string $key
69+
* @param string $message
70+
*/
71+
protected static function insertTranslation(Translations $translations, $key, $message)
72+
{
73+
$context_glue = '\u0004';
74+
$key = explode($context_glue, $key);
6975

70-
$entry = $translations->insert($context, $original, $plural);
71-
$entry->setTranslation($translation);
72-
$entry->setPluralTranslation($plural_translation);
73-
}
76+
$context = isset($key[1]) ? array_shift($key) : '';
77+
$original = array_shift($key);
78+
$plural = array_shift($message);
79+
$translation = array_shift($message);
80+
$plural_translation = array_shift($message);
81+
82+
$entry = $translations->insert($context, $original, $plural);
83+
$entry->setTranslation($translation);
84+
$entry->setPluralTranslation($plural_translation);
7485
}
7586
}

0 commit comments

Comments
 (0)