classes/LanguageMixer.php
public function addStringsFromAnotherLanguage($destContents, $srcArray)
    {
        // 1. Find array keys that exists in the source array and don't exist in the destination array
        // 2. Merge the arrays recursively
        // 3. To find which lines were added:
        //    3.1 get a YAML representation of the destination array
        //    3.2 walk through the missing paths obtained in step 1 and for each path:
        //    3.3 find its path and its corresponding line in the string from 3.1.

        $result = [
            'strings' => '',
            'mismatch' => false,
            'updatedLines' => [],
        ];

        try
        {
            $destArray = Yaml::parse($destContents);
        }
        catch (Exception $ex) {
            throw new ApplicationException(sprintf('Cannot parse the YAML content: %s', $ex->getMessage()));
        }

        if (!$destArray) {
            $result['strings'] = $this->arrayToYaml($srcArray);
            return $result;
        }

        $mismatch = false;
        $missingPaths = $this->findMissingPaths($destArray, $srcArray, $mismatch);
        $mergedArray = self::arrayMergeRecursive($srcArray, $destArray);

        $destStrings = $this->arrayToYaml($mergedArray);
        $addedLines = $this->getAddedLines($destStrings, $missingPaths);

        $result['strings'] = $destStrings;
        $result['updatedLines'] = $addedLines['lines'];
        $result['mismatch'] = $mismatch || $addedLines['mismatch'];

        return $result;
    }
public function addStringsFromAnotherLanguage($destContents, $srcArray)
    {
        // 1. Find array keys that exists in the source array and don't exist in the destination array
        // 2. Merge the arrays recursively
        // 3. To find which lines were added:
        //    3.1 get a YAML representation of the destination array
        //    3.2 walk through the missing paths obtained in step 1 and for each path:
        //    3.3 find its path and its corresponding line in the string from 3.1.

        $result = [
            'strings' => '',
            'mismatch' => false,
            'updatedLines' => [],
        ];

        try
        {
            $destArray = Yaml::parse($destContents);
        }
        catch (Exception $ex) {
            throw new ApplicationException(sprintf('Cannot parse the YAML content: %s', $ex->getMessage()));
        }

        if (!$destArray) {
            $result['strings'] = $this->arrayToYaml($srcArray);
            return $result;
        }

        $mismatch = false;
        $missingPaths = $this->findMissingPaths($destArray, $srcArray, $mismatch);
        $mergedArray = self::arrayMergeRecursive($srcArray, $destArray);

        $destStrings = $this->arrayToYaml($mergedArray);
        $addedLines = $this->getAddedLines($destStrings, $missingPaths);

        $result['strings'] = $destStrings;
        $result['updatedLines'] = $addedLines['lines'];
        $result['mismatch'] = $mismatch || $addedLines['mismatch'];

        return $result;
    }
public function addStringsFromAnotherLanguage ( $ destContents , $ srcArray ) { // 1. Find array keys that exists in the source array and don't exist in the destination array // 2. Merge the arrays recursively // 3. To find which lines were added: //    3.1 get a YAML representation of the destination array //    3.2 walk through the missing paths obtained in step 1 and for each path: //    3.3 find its path and its corresponding line in the string from 3.1. $ result = [ 'strings' => '' , 'mismatch' => false , 'updatedLines' => [ ] , ] ; try { $ destArray = Yaml :: parse ( $ destContents ) ; } catch ( Exception $ ex ) { throw new ApplicationException ( sprintf ( 'Cannot parse the YAML content: %s' , $ ex -> getMessage ( ) ) ) ; } if ( ! $ destArray ) { $ result [ 'strings' ] = $ this -> arrayToYaml ( $ srcArray ) ; return $ result ; } $ mismatch = false ; $ missingPaths = $ this -> findMissingPaths ( $ destArray , $ srcArray , $ mismatch ) ; $ mergedArray = self :: arrayMergeRecursive ( $ srcArray , $ destArray ) ; $ destStrings = $ this -> arrayToYaml ( $ mergedArray ) ; $ addedLines = $ this -> getAddedLines ( $ destStrings , $ missingPaths ) ; $ result [ 'strings' ] = $ destStrings ; $ result [ 'updatedLines' ] = $ addedLines [ 'lines' ] ; $ result [ 'mismatch' ] = $ mismatch || $ addedLines [ 'mismatch' ] ; return $ result ; }
Merges two localization languages and return merged YAML string and indexes of added lines.
Merges two localization languages and return merged YAML string and indexes of added lines .