public static function populateRedisDictionary(
        \Redis $redis,
        $dictPath,
        array $languages = null,
        $fileCallback = null
    ) {
        $redisDictionary = new RedisDictionary($redis);

        $dictPath = rtrim($dictPath, '/');

        if (!is_dir($dictPath)) {
            throw new \InvalidArgumentException(sprintf(
                'The directory "%s" not found.',
                $dictPath
            ));
        }

        if ($fileCallback && !is_callable($fileCallback)) {
            throw new \InvalidArgumentException(sprintf(
                'The callback must be a callable, %s given.',
                is_object($fileCallback) ? get_class($fileCallback) : gettype($fileCallback)
            ));
        }

        $files = glob($dictPath . '/*');

        foreach ($files as $file) {
            $fileName = substr($file, strlen($dictPath) + 1);

            if (!preg_match('/^(.+)\.(.+)$/', $fileName, $tmp)) {
                throw new \RuntimeException(sprintf(
                    'Could not parse language from file name "%s".',
                    $fileName
                ));
            }

            $lang = $tmp[1];
            $ext = $tmp[2];

            if ($languages !== null && !in_array($lang, $languages)) {
                continue;
            }

            if ('php' == $ext) {
                // PHP File dictionary
                $words = include $file;
            } elseif (in_array($ext, array('dict', 'txt'))) {
                // Base dictionary: one word (or more then 1) on one line
                $words = file($file);
            } else {
                throw new \RuntimeException(sprintf(
                    'Undefined file with ext "%s". Supported "php" and "dict".',
                    $ext
                ));
            }

            $words = array_map('trim', $words);

            foreach ($words as $wordLine) {
                $wordsLine = explode(' ', $wordLine);

                $wordsLine = array_map('trim', $wordsLine);

                foreach ($wordsLine as $word) {
                    if (!$word) {
                        continue;
                    }

                    $redisDictionary->addWord($lang, $word);
                }
            }

            if ($fileCallback) {
                call_user_func($fileCallback, $file, count($words));
            }

            unset ($words);
            gc_collect_cycles();
        }
    }