/var/www/hkosl.com/demo_google/application/vendor/gettext/gettext/src/Extractors/Jed.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

namespace Gettext\Extractors;

use 
Gettext\Translations;

/**
 * Class to get gettext strings from json files.
 */
class Jed extends Extractor implements ExtractorInterface
{
    
/**
     * {@inheritdoc}
     */
    
public static function fromString($stringTranslations $translations, array $options = [])
    {
        
self::extract(json_decode($stringtrue), $translations);
    }

    
/**
     * Handle an array of translations and append to the Translations instance.
     *
     * @param array        $content
     * @param Translations $translations
     */
    
public static function extract(array $contentTranslations $translations)
    {
        
$messages current($content);
        
$headers = isset($messages['']) ? $messages[''] : null;
        unset(
$messages['']);

        if (!empty(
$headers['domain'])) {
            
$translations->setDomain($headers['domain']);
        }

        if (!empty(
$headers['lang'])) {
            
$translations->setLanguage($headers['lang']);
        }

        if (!empty(
$headers['plural-forms'])) {
            
$translations->setHeader(Translations::HEADER_PLURAL$headers['plural-forms']);
        }

        
$context_glue '\u0004';

        foreach (
$messages as $key => $translation) {
            
$key explode($context_glue$key);
            
$context = isset($key[1]) ? array_shift($key) : '';

            
$translations->insert($contextarray_shift($key))
                ->
setTranslation(array_shift($translation))
                ->
setPluralTranslations($translation);
        }
    }
}