| @@ 10-29 (lines=20) @@ | ||
| 7 | /** |
|
| 8 | * Class to get gettext strings from plain json. |
|
| 9 | */ |
|
| 10 | class JsonDictionary extends Extractor implements ExtractorInterface |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * {@inheritdoc} |
|
| 14 | */ |
|
| 15 | public static function fromString($string, Translations $translations = null, $file = '') |
|
| 16 | { |
|
| 17 | if ($translations === null) { |
|
| 18 | $translations = new Translations(); |
|
| 19 | } |
|
| 20 | ||
| 21 | if (($entries = json_decode($string, true))) { |
|
| 22 | foreach ($entries as $original => $translation) { |
|
| 23 | $translations->insert(null, $original)->setTranslation($translation); |
|
| 24 | } |
|
| 25 | } |
|
| 26 | ||
| 27 | return $translations; |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||
| @@ 11-30 (lines=20) @@ | ||
| 8 | /** |
|
| 9 | * Class to get gettext strings from plain json. |
|
| 10 | */ |
|
| 11 | class YamlDictionary extends Extractor implements ExtractorInterface |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * {@inheritdoc} |
|
| 15 | */ |
|
| 16 | public static function fromString($string, Translations $translations = null, $file = '') |
|
| 17 | { |
|
| 18 | if ($translations === null) { |
|
| 19 | $translations = new Translations(); |
|
| 20 | } |
|
| 21 | ||
| 22 | if (($entries = Yaml::parse($string))) { |
|
| 23 | foreach ($entries as $original => $translation) { |
|
| 24 | $translations->insert(null, $original)->setTranslation($translation); |
|
| 25 | } |
|
| 26 | } |
|
| 27 | ||
| 28 | return $translations; |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||