function lexicon($path, $ttl = 0)
{
$languages = $this->languages ?: explode(',', $this->fallback);
$cache = Cache::instance();
if ($cache->exists($hash = $this->hash(implode(',', $languages)) . '.dic', $lex)) {
return $lex;
}
$lex = [];
foreach ($languages as $lang) {
foreach ($this->split($path) as $dir) {
if ((is_file($file = ($base = $dir . $lang) . '.php') || is_file($file = $base . '.php')) && is_array($dict = (require $file))) {
$lex += $dict;
} elseif (is_file($file = $base . '.ini')) {
preg_match_all('/(?<=^|\\n)(?:' . '\\[(?<prefix>.+?)\\]|' . '(?<lval>[^\\h\\r\\n;].*?)\\h*=\\h*' . '(?<rval>(?:\\\\\\h*\\r?\\n|.+?)*)' . ')(?=\\r?\\n|$)/', $this->read($file), $matches, PREG_SET_ORDER);
if ($matches) {
$prefix = '';
foreach ($matches as $match) {
if ($match['prefix']) {
$prefix = $match['prefix'] . '.';
} elseif (!array_key_exists($key = $prefix . $match['lval'], $lex)) {
$lex[$key] = trim(preg_replace('/\\\\\\h*\\r?\\n/', '', $match['rval']));
}
}
}
}
}
}
if ($ttl) {
$cache->set($hash, $lex, $ttl);
}
return $lex;
}