symfony/translation · error · InvalidResourceException

Invalid resource provided

Error message

Invalid resource provided: "%s"; Errors: 

What it means

The DOM parsed successfully but failed XLIFF schema validation via XliffUtils::validateSchema(); the loader throws InvalidResourceException listing all schema errors after this prefix. The file must be valid XLIFF 1.2 or 2.0 per its declared version.

Solutions

  1. Read the appended XliffUtils::getErrorsAsString() output to see each schema violation.
  2. Fix the file so it conforms to XLIFF 1.2 or 2.0 (correct root <xliff> with proper xmlns and version attributes).
  3. Re-export from the CAT tool choosing a standard XLIFF profile.
  4. Validate locally first with xmllint against the official XLIFF schema before loading.

Example fix

// before
<xliff version="1.2"><file>...</file></xliff> <!-- missing xmlns -->
// after
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"><file>...</file></xliff>
Defensive patterns

Strategy: validation

Validate before calling

$dom = \Symfony\Component\Config\Util\XmlUtils::loadFile($resource);
if ($errors = \Symfony\Component\Translation\Util\XliffUtils::validateSchema($dom)) {
    throw new \RuntimeException(XliffUtils::getErrorsAsString($errors));
}

Try / catch

try {
    $catalogue = $loader->load($resource, $locale);
} catch (InvalidResourceException $e) {
    if (str_contains($e->getMessage(), 'Invalid resource provided')) {
        // surface XliffUtils::getErrorsAsString details to translators
    }
    throw $e;
}

Prevention

When it happens

Trigger: Calling XliffFileLoader::load() with XML that is well-formed but violates the XLIFF schema — wrong root element/namespace, invalid attributes, missing required units, or a version attribute not matching the actual structure.

Common situations: Files exported by custom tools with non-standard XLIFF; XLIFF 2.0 content declared as version 1.2 or vice versa; missing xliff namespace declarations; hand-built translation files.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of symfony/translation@ae9e8a51bc (2026-09-15). Data as JSON: /api/errors/93d41b65d43bc3f2. Report an issue: GitHub.

Appendix: source

Thrown at Loader/XliffFileLoader.php:63

            }

            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
    {
        $xliffVersion = XliffUtils::getVersionNumber($dom);

        if ('1.2' === $xliffVersion) {
            $this->extractXliff1($dom, $catalogue, $domain);

View on GitHub (pinned to ae9e8a51bc)