Extract all translations from the provided file
Remove all translations containing :
- $  -> auto-generated translation cannot be supported
- :: -> package translations are not taken in account

@param string $path the file path

@return array
437947
protected function extractTranslationFromFile($path)
    {
        $result = [];
        $string = file_get_contents($path);

        foreach (array_flatten($this->config('trans_methods', [])) as $method) {
            preg_match_all($method, $string, $matches);

            foreach ($matches[1] as $k => $v) {
                if (strpos($v, '$') !== false) {
                    unset($matches[1][$k]);
                }
                if (strpos($v, '::') !== false) {
                    unset($matches[1][$k]);
                }
            }

            $result = array_merge($result, array_flip($matches[1]));
        }

        return $result;
    }
647592
public static function GetDirContent($path)
    {
        $files = array();
        $directory = opendir($path);

        while(($file = readdir($directory)) !== false)
        {
            $full_path = $path . "/" . $file;

            if(is_file($full_path))
            {
                $files[] = $full_path;
            }
            elseif($file != "." && $file != ".." && is_dir($full_path))
            {
                $files[] = $full_path;
                $files = array_merge($files, self::GetDirContent($full_path));
            }
        }

        closedir($directory);

        return $files;
    }
144282
protected function getPathAsArray($path)
    {
        $path = str_replace('\/', '@@@', $path);
        $path = rtrim($path, "/");
        $segments = explode('/', $path);
        return array_map(function($item) {
            return str_replace('@@@', '/', $item);
        }, $segments);
    }
91131
public static function findDirs(string $path): array
    {
        $result = [];

        try {
            static::validatePath($path);
            $path = new DirectoryIterator($path);
        } catch (InvalidArgumentException $e) {
            return $result;
        } catch (UnexpectedValueException $e) {
            return $result;
        }

        foreach ($path as $dir) {
            if ($dir->isDot()) {
                continue;
            }
            if (!$dir->isDir()) {
                continue;
            }
            $result[] = $dir->getFilename();
        }
        asort($result);

        return $result;
    }
648395
protected function getConfigurationFiles($path)
    {
        $files = [];

        foreach (Finder::create()->files()->name('*.php')->in($path) as $file) {
            $directory = $this->getNestedDirectory($file, $path);
            $files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath();
        }

        ksort($files, SORT_NATURAL);

        return $files;
    }
282687
public static function get_migrations( $path )
	{
		$objects = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $path ), \RecursiveIteratorIterator::SELF_FIRST );
		
		$files = array();
		
		foreach( $objects as $name => $object )
		{
			if ( \CCStr::extension( $name ) == 'sql' )
			{
				$files[\CCStr::cut( substr( basename( $name ), strrpos( basename( $name ),  '_' )+1 ), '.' )] = $name;
			}
		}
		
		ksort( $files );
		
		return $files;
	}
678392
public static function splitNameFromPath($path)
    {
        $name = static::nameFromPath($path);
        $path = static::trimFileName($path);

        return [$path, $name];
    }
75051
public function getRedeemScriptByPath($path) {
        $walletScript = $this->getWalletScriptByPath($path);

        $redeemScript = $walletScript->isP2SH() ? $walletScript->getRedeemScript() : null;
        $witnessScript = $walletScript->isP2WSH() ? $walletScript->getWitnessScript() : null;
        return [$walletScript->getAddress()->getAddress(), $redeemScript, $witnessScript];
    }
666032
public function importTranslations($path, $type)
    {
        $separator = app('config')->get('antares/translations::export.separator');
        $content   = explode(PHP_EOL, file_get_contents($path));
        $list      = [];
        foreach ($content as $index => $line) {
            if ($index == 0) {
                continue;
            }
            array_push($list, explode($separator, $line));
        }


        $locale   = $list[0][1];
        $language = Languages::where('code', $locale)->first();
        try {
            DB::transaction(function() use($language, $list, $type) {
                $area   = request()->segment(6);
                DB::table('tbl_translations')->where('lang_id', $language->id)->where('area', $area)->delete();
                $insert = [];
                foreach ($list as $item) {
                    if (!isset($item[2]) or ! isset($item[3])) {
                        continue;
                    }
                    try {
                        $value = iconv('WINDOWS-1250', 'UTF-8', $item[3]);
                    } catch (Exception $ex) {
                        $value = $item[3];
                    }

                    $insert[] = [
                        'locale'  => $language->code,
                        'area'    => $area,
                        'group'   => 'antares/' . $item[0],
                        'lang_id' => $language->id,
                        'key'     => trim($item[2], '"'),
                        'value'   => trim($value, '"'),
                    ];
                }
                DB::table('tbl_translations')->insert($insert);
            });
            return true;
        } catch (Exception $e) {
            Log::warning($e);
            return false;
        }
    }
298093
public function parse($path)
    {
        $parser = new Parser();
        $document = $parser->parse(file_get_contents($path));
        $properties = $document->getYAML();
        $properties['__content'] = $document->getContent();

        return $properties;
    }
494388
public function getTranslationsFromPath($path, $fileType)
    {
        // remove vendor/locomotivemtl/charcoal-app
        $base  = $this->appConfig->get('base_path');
        $glob  = $this->globRecursive($base.$path.'*.'.$fileType);
        $regex = $this->regEx($fileType);

        $translations = [];

        // Array index for the preg_match.
        $index = 'text';
        // if ($fileType == 'php') {
        //     $index = 'text';
        // }

        $k = 0;

        $this->climate()->inline('.');
        // Loop files to get original text.
        foreach ($glob as $k => $file) {
            $k++;
            $this->climate()->inline('.');
            $text = file_get_contents($file);

            if (preg_match($regex, $text)) {
                preg_match_all($regex, $text, $array);

                $i = 0;
                $t = count($array[$index]);
                $locales = $this->locales();

                for (; $i < $t; $i++) {
                    $this->climate()->inline('.');
                    $orig = $array[$index][$i];
                    foreach ($locales as $lang) {
                        $this->climate()->inline('.');
                        $this->translator()->setLocale($lang);
                        // By calling translate, we make sure all existings translations are taking into consideration.

                        $translations[$lang][$orig] = stripslashes($this->translator()->translate($orig));
                    }
                }
            }
        }
        $this->climate()->out('.');
        $this->climate()->green()->out('Translations parsed from '.$path);
        return $translations;
    }
982824
private static function get_language_plugin_list( $path ) {
		$languages = [];

		// Try to open the given directory.
		$handle = \opendir( $path );
		if ( false === $handle ) {
			// Abort.
			return $languages; // @codeCoverageIgnore
		}

		// Read all files in directory.
		$file = \readdir( $handle );
		while ( $file ) {
			// We only want the JSON files.
			if ( '.json' === \substr( $file, -5 ) ) {
				$file_content = \file_get_contents( $path . $file );
				if ( \preg_match( '/"language"\s*:\s*((".+")|(\'.+\'))\s*,/', $file_content, $matches ) ) {
					$language_name = \substr( $matches[1], 1, -1 );
					$language_code = \substr( $file, 0, -5 );

					$languages[ $language_code ] = $language_name;
				}
			}

			// Read next file.
			$file = \readdir( $handle );
		}
		\closedir( $handle );

		// Sort translated language names according to current locale.
		\asort( $languages );

		return $languages;
	}
494418
private function lsdir(string $path): array
    {
        $result = @scandir($path);

        if (false === $result) {
            $message = 'Could not read directory.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return array_values(array_diff($result, ['.', '..']));
    }
455881
protected function loadFile($path): array
    {
        $reader = ReaderFactory::get($this->builder, $path);

        return $reader->read($path);
    }
222083
public function getExcludePaths($path)
    {
        $excludePaths = [];

        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
        $objects = new \RegexIterator($iterator, '/.*(.php)$/', \RecursiveRegexIterator::GET_MATCH);

        foreach ($objects as $filename => $object) {
            if (preg_filter($this->ignoredFolder, [], $filename)) {
                $excludePaths[] = dirname($filename);
            }
        }

        $excludePaths = array_unique($excludePaths);

        return $excludePaths;
    }
383945
private function get_files_from_folders( $path ) {

		$items = $this::get_folder_contents( $path );

		foreach ( $items as $type => &$location ) {
			$location = $this::get_folder_contents( trailingslashit( $location ) );
			sort( $location );
		}

		return $items;
	}
1218785
public function extract($path) {

        if (empty($path)) {
            return $this->props;
        }
        // Simple paths.
        if (!preg_match('/[{\[]/', $path)) {
            return (array)$this->get($path);
        }
        if (strpos($path, '[') === false) {
            $tokens = explode('/', $path);
        } else {
            $tokens = $this->_tokenize($path, '/', '[', ']');
        }
        $_key = '__set_item__';
        $context = array($_key => array($this->props));
        foreach ($tokens as $token) {
            $next = array();
            list($token, $conditions) = $this->_splitConditions($token);
            foreach ($context[$_key] as $item) {
                foreach ((array)$item as $k => $v) {
                    if ($this->_matchToken($k, $token)) {
                        $next[] = $v;
                    }
                }
            }
            // Filter for attributes.
            if ($conditions) {
                $filter = array();
                foreach ($next as $item) {
                    if (is_array($item) && $this->_matches($item, $conditions)) {
                        $filter[] = $item;
                    }
                }
                $next = $filter;
            }
            $context = array($_key => $next);
        }
        return $context[$_key];
    }