{"record":{"id":"9cb616cd267baf4e","repo":"symfony/translation","slug":"unable-to-load-s","errorCode":null,"errorMessage":"Unable to load \"%s\".","messagePattern":"Unable to load \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/QtFileLoader.php","lineNumber":45,"sourceCode":"{\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 QT format requires the Symfony Config component.');\n        }\n\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        try {\n            $dom = XmlUtils::loadFile($resource);\n        } catch (\\InvalidArgumentException $e) {\n            throw new InvalidResourceException(\\sprintf('Unable to load \"%s\".', $resource), $e->getCode(), $e);\n        }\n\n        $internalErrors = libxml_use_internal_errors(true);\n        libxml_clear_errors();\n\n        $xpath = new \\DOMXPath($dom);\n        $nodes = $xpath->evaluate('//TS/context/name[text()=\"'.$domain.'\"]');\n\n        $catalogue = new MessageCatalogue($locale);\n        if (1 == $nodes->length) {\n            $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message');\n            foreach ($translations as $translation) {\n                $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue;\n\n                if ($translationValue) {\n                    $catalogue->set(\n                        (string) $translation->getElementsByTagName('source')->item(0)->nodeValue,\n                        $translationValue,","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/QtFileLoader.php#L27-L63","documentation":"XmlUtils::loadFile() validates the QT TS file against its DTD/schema; failures surface as InvalidArgumentException which the loader re-wraps as InvalidResourceException('Unable to load \"<file>\".'). The XML is unreadable, malformed, or fails QT's DTD validation.","triggerScenarios":"load() on a .ts file that is not well-formed XML, has wrong encoding, is an HTML/other-XML file misnamed .ts, or violates the QT translation DTD — raised in testLoad paths.","commonSituations":"Truncated downloads of .ts files, editors saving with wrong encoding, manually edited XML introducing syntax errors, DTD unreachable when validating against remote entities in air-gapped environments.","solutions":["Validate the XML independently: `xmllint --noout file.ts` to see the precise parse error and line.","Fix the malformed XML (unclosed tags, bad entities, encoding declaration).","Confirm the file is actually a QT TS file, not another XML dialect renamed to .ts.","Re-export the .ts from Qt Linguist / lupdate; if DTD fetching is blocked, allow local DTD access or use a fully offline-valid file.","Check the previous exception in the chain (InvalidArgumentException) for the underlying libxml message."],"exampleFix":"// before (messages.ts)\n<?xml version=\"1.0\"?>\n<TS><context><name>app</name>  // unclosed tags\n// after\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE TS>\n<TS version=\"2.0\"><context><name>app</name></context></TS>","handlingStrategy":"try-catch","validationCode":"libxml_use_internal_errors(true);\n$dom = new \\DOMDocument();\nif (!$dom->load($resource)) {\n    $err = libxml_get_last_error();\n    throw new \\RuntimeException(sprintf('%s is not valid XML: %s at line %d', $resource, trim($err->message), $err->line));\n}\nlibxml_clear_errors();","typeGuard":null,"tryCatchPattern":"try {\n    $catalogue = $loader->load($resource, $locale);\n} catch (InvalidResourceException $e) {\n    error_log('QT XML load failed: '.$e->getMessage().' previous: '.$e->getPrevious()?->getMessage());\n    $catalogue = new MessageCatalogue($locale);\n}","preventionTips":["Run xmllint --noout against .ts files in CI","Re-export .ts files from lupdate/Qt Linguist instead of hand-editing","Always inspect getPrevious() for the underlying libxml message","Ensure correct UTF-8 encoding declarations in XML headers"],"tags":["qt","xml","translation","parse-error"],"backgroundTag":"xml-parse-error","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"}