symfony/translation · error · InvalidResourceException
Unable to load
Error message
Unable to load "%s":
What it means
XmlUtils::parse()/loadFile() failed to produce a DOM document (malformed XML, unreadable file, or invalid XML); the loader wraps the underlying exception (InvalidArgumentException, XmlParsingException, or InvalidXmlException) in an InvalidResourceException with this prefix. The original message is appended after the colon.
Solutions
- Validate the XLIFF file with xmllint or an XML editor and fix syntax errors.
- Read the chained exception message (after the colon) to locate the exact XML problem (line/column).
- Re-export the file from the translation tool ensuring valid XML and UTF-8 encoding.
- Run the schema validation separately (XliffUtils::validateSchema) to confirm XML well-formedness first.
Defensive patterns
Strategy: try-catch
Validate before calling
$xml = @file_get_contents($resource);
if (false === $xml) { throw new \RuntimeException('Unreadable resource'); }
if (false === simplexml_load_string($xml)) { throw new \RuntimeException('Malformed XML in '.$resource); } Try / catch
try {
$catalogue = $loader->load($resource, $locale);
} catch (InvalidResourceException $e) {
$this->logger->error('XLIFF load failed', ['resource' => $resource, 'reason' => $e->getMessage(), 'previous' => $e->getPrevious()?->getMessage()]);
throw $e;
} Prevention
- Always inspect $e->getPrevious() for the precise XML error (line/column).
- Lint XLIFF files with xmllint in CI before shipping.
- Export files in UTF-8 from translation tools.
- Avoid hand-editing XLIFF without re-validating.
When it happens
Trigger: Calling XliffFileLoader::load() with an XLIFF string or file containing syntactically invalid XML, or a file XmlUtils cannot load (unreadable permissions, encoding issues).
Common situations: Hand-edited XLIFF files with unclosed tags; files exported by third-party tools with invalid characters; truncated downloads; wrong file encoding (not UTF-8).
Related errors
- Not a valid XLIFF namespace
- Unable to load " ".
- Loading translations from the Xliff format requires the…
- This is not a local file
- File " " not found.
AI-assisted analysis of symfony/translation@ae9e8a51bc (2026-09-15).
Data as JSON: /api/errors/89911edeb36200ec.
Report an issue: GitHub.
Appendix: source
Thrown at Loader/XliffFileLoader.php:59
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(\sprintf('File "%s" not found.', $resource));
}
if (!is_file($resource)) {
throw new InvalidResourceException(\sprintf('This is neither a file nor an XLIFF string "%s".', $resource));
}
}
try {
if ($this->isXmlString($resource)) {
$dom = XmlUtils::parse($resource);
} else {
$dom = XmlUtils::loadFile($resource);
}
} catch (\InvalidArgumentException|XmlParsingException|InvalidXmlException $e) {
throw new InvalidResourceException(\sprintf('Unable to load "%s": ', $resource).$e->getMessage(), $e->getCode(), $e);
}
if ($errors = XliffUtils::validateSchema($dom)) {
throw new InvalidResourceException(\sprintf('Invalid resource provided: "%s"; Errors: ', $resource).XliffUtils::getErrorsAsString($errors));
}
$catalogue = new MessageCatalogue($locale);
$this->extract($dom, $catalogue, $domain);
if (is_file($resource) && class_exists(FileResource::class)) {
$catalogue->addResource(new FileResource($resource));
}
return $catalogue;
}
private function extract(\DOMDocument $dom, MessageCatalogue $catalogue, string $domain): void
{View on GitHub (pinned to ae9e8a51bc)