{"record":{"id":"4461b202f3e67baa","repo":"symfony/translation","slug":"this-is-neither-a-file-nor-an-xliff-string-s","errorCode":null,"errorMessage":"This is neither a file nor an XLIFF string \"%s\".","messagePattern":"This is neither a file nor an XLIFF string \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/XliffFileLoader.php","lineNumber":48,"sourceCode":"class XliffFileLoader implements LoaderInterface\n{\n    public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue\n    {\n        if (!class_exists(XmlUtils::class)) {\n            throw new RuntimeException('Loading translations from the Xliff format requires the Symfony Config component.');\n        }\n\n        if (!$this->isXmlString($resource)) {\n            if (!stream_is_local($resource)) {\n                throw new InvalidResourceException(\\sprintf('This is not a local file \"%s\".', $resource));\n            }\n\n            if (!file_exists($resource)) {\n                throw new NotFoundResourceException(\\sprintf('File \"%s\" not found.', $resource));\n            }\n\n            if (!is_file($resource)) {\n                throw new InvalidResourceException(\\sprintf('This is neither a file nor an XLIFF string \"%s\".', $resource));\n            }\n        }\n\n        try {\n            if ($this->isXmlString($resource)) {\n                $dom = XmlUtils::parse($resource);\n            } else {\n                $dom = XmlUtils::loadFile($resource);\n            }\n        } catch (\\InvalidArgumentException|XmlParsingException|InvalidXmlException $e) {\n            throw new InvalidResourceException(\\sprintf('Unable to load \"%s\": ', $resource).$e->getMessage(), $e->getCode(), $e);\n        }\n\n        if ($errors = XliffUtils::validateSchema($dom)) {\n            throw new InvalidResourceException(\\sprintf('Invalid resource provided: \"%s\"; Errors: ', $resource).XliffUtils::getErrorsAsString($errors));\n        }\n\n        $catalogue = new MessageCatalogue($locale);","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/XliffFileLoader.php#L30-L66","documentation":"The resource is a local, existing path but is neither a regular file nor an XML string — typically a directory — so the loader throws InvalidResourceException. is_file() distinguishes regular files from directories and special files.","triggerScenarios":"Passing a directory path (e.g. the translations folder itself) as $resource to XliffFileLoader::load().","commonSituations":"Configuration mistake where a directory configured for translation lookup is fed to the loader directly instead of individual files.","solutions":["Pass a single .xlf/.xliff file path, not a directory.","Iterate the directory yourself (glob('translations/*.xlf')) and call load() per file.","Validate with is_file($resource) before calling load()."],"exampleFix":"// before\n$loader->load('translations/', 'en'); // directory\n// after\nforeach (glob('translations/*.xlf') as $file) {\n    $loader->load($file, 'en');\n}","handlingStrategy":"validation","validationCode":"if (!is_file($resource) && !str_starts_with(ltrim((string) $resource), '<?xml')) {\n    throw new \\InvalidArgumentException(sprintf('Expected an XLIFF file, got: %s', $resource));\n}","typeGuard":null,"tryCatchPattern":"try {\n    $catalogue = $loader->load($resource, $locale);\n} catch (InvalidResourceException $e) {\n    if (str_contains($e->getMessage(), 'neither a file nor an XLIFF string')) {\n        // you probably passed a directory; enumerate files instead\n    }\n}","preventionTips":["Pass file paths, never directory paths, to the loader.","Use glob()/Finder to expand directories into per-file load calls.","Add a unit test asserting configured resource paths are files."],"tags":["php","xliff","invalid-resource"],"backgroundTag":"invalid-argument-value","analyzedSha":"ae9e8a51bc29780d63c7f9efd6005d7c875e100b","analyzedAt":"2026-09-15T22:29:15.305Z","contentChangedAt":"2026-09-15T22:29:15.305Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}