RRule\RRule::i18nLoad PHP Method

i18nLoad() protected static method

Will load the basic first (e.g. "en") and then the region-specific if any (e.g. "en_GB"), merging as necessary. So region-specific translation files don't need to redefine every strings.
protected static i18nLoad ( string $locale, string | null $fallback = null ) : array
$locale string
$fallback string | null
return array
    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;
    }