protected static function i18nLoad($locale, $fallback = null)
{
if (!preg_match('/^([a-z]{2})(?:(?:_|-)[A-Z][a-z]+)?(?:(?:_|-)([A-Z]{2}))?(?:(?:_|-)[A-Z]*)?(?:\\.[a-zA-Z\\-0-9]*)?$/', $locale, $matches)) {
throw new \InvalidArgumentException('The locale option does not look like a valid locale: ' . $locale);
}
$files = array();
if (isset($matches[2])) {
$files[] = $matches[1];
}
$files[] = $locale;
$result = array();
foreach ($files as $file) {
$path = __DIR__ . "/i18n/{$file}.php";
if (isset(self::$i18n[$file])) {
$result = array_merge($result, self::$i18n[$file]);
} elseif (is_file($path) && is_readable($path)) {
self::$i18n[$file] = (include $path);
$result = array_merge($result, self::$i18n[$file]);
} else {
self::$i18n[$file] = array();
}
}
if (empty($result)) {
if (!is_null($fallback)) {
return self::i18nLoad($fallback);
}
throw new \RuntimeException("Failed to load translations for '{$locale}'");
}
return $result;
}