/** * Load the language from a file. * * @param File $file Language file to load. * * @throws Exception Throws if an error occurred. */ public function load($file) { // Make sure the file a proper instance if (!$file instanceof File) { throw new Exception('Failed to load language file, invalid file!'); } // Make sure the file exists if (!$file->isFile()) { throw new Exception('Failed to load language file, the specified file doesn\'t exist!'); } // Gather and set the language tag from the file name, also make sure it's valid $tag = trim($file->getBasename($file->getExtension(true))); if (strlen($tag) <= 0) { throw new Exception('An error occurred when loading a language file.'); } $this->tag = $tag; // Load the language file, make sure it succeed $langContent = parse_ini_file($file->getAbsolutePath(), true, INI_SCANNER_RAW); if ($langContent === false) { throw new Exception('An error occurred when loading a language file.'); } // Set the language content $this->content = $langContent; }