{"record":{"id":"85e4ef0a26004bd1","repo":"symfony/translation","slug":"cannot-load-resource-s-icuresfileloader","errorCode":null,"errorMessage":"Cannot load resource \"%s\".","messagePattern":"Cannot load resource \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidResourceException","httpStatus":null,"severity":"error","filePath":"Loader/IcuResFileLoader.php","lineNumber":43,"sourceCode":"{\n    public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue\n    {\n        if (!stream_is_local($resource)) {\n            throw new InvalidResourceException(\\sprintf('This is not a local file \"%s\".', $resource));\n        }\n\n        if (!is_dir($resource)) {\n            throw new NotFoundResourceException(\\sprintf('File \"%s\" not found.', $resource));\n        }\n\n        try {\n            $rb = new \\ResourceBundle($locale, $resource);\n        } catch (\\Exception) {\n            $rb = null;\n        }\n\n        if (!$rb) {\n            throw new InvalidResourceException(\\sprintf('Cannot load resource \"%s\".', $resource));\n        } elseif (intl_is_failure($rb->getErrorCode())) {\n            throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());\n        }\n\n        $messages = $this->flatten($rb);\n        $catalogue = new MessageCatalogue($locale);\n        $catalogue->add($messages, $domain);\n\n        if (class_exists(DirectoryResource::class)) {\n            $catalogue->addResource(new DirectoryResource($resource));\n        }\n\n        return $catalogue;\n    }\n\n    /**\n     * Flattens an ResourceBundle.\n     *","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/IcuResFileLoader.php#L25-L61","documentation":"IcuResFileLoader loads translations from compiled ICU .res resource bundles. After constructing a ResourceBundle, it throws InvalidResourceException when the bundle could not be loaded (null/false result), meaning the .res file is missing, corrupt, or not a valid ICU bundle for the requested locale.","triggerScenarios":"Calling load($resource, $locale) where the ResourceBundle constructor returns no usable bundle — the $resource path points to a nonexistent or corrupt .res file, or ICU cannot resolve the bundle for the given locale. Raised in tests testDatEnglishLoad/testDatFrenchLoad paths.","commonSituations":"Missing .dat/.res translation files after deployment, ICU data not built (packaging steps skipped), wrong resource path or locale naming (e.g. 'en' vs 'en_US'), corrupted bundles from a broken intl build.","solutions":["Verify the .res/.dat resource file exists at the exact path passed to load() and is readable.","Rebuild the ICU resource bundles with msgfmt / genrb for the locales you need.","Confirm the locale string matches the bundle's locale naming; try loading the bundle directly with new ResourceBundle($locale, $resource) to see ICU's error code.","Check the intl/ICU extension version compatibility with the bundle format version."],"exampleFix":"// before\n$loader->load('/resources/messages.en.res', 'en'); // file missing\n// after\nif (!is_file('/resources/messages.en.res')) {\n    throw new \\RuntimeException('Run genrb to build messages.en.res first');\n}\n$loader->load('/resources/messages.en.res', 'en');","handlingStrategy":"validation","validationCode":"if (!is_file($resource) || !is_readable($resource)) {\n    throw new \\RuntimeException(sprintf('ICU resource missing or unreadable: %s', $resource));\n}\n$probe = new \\ResourceBundle($locale, $resource);\nif (!$probe || intl_is_failure($probe->getErrorCode())) {\n    throw new \\RuntimeException(sprintf('ICU cannot load bundle: %s', $probe ? $probe->getErrorMessage() : 'null bundle'));\n}","typeGuard":"function isValidIcuBundle(string $locale, string $resource): bool {\n    $rb = @new \\ResourceBundle($locale, $resource);\n    return $rb !== null && !intl_is_failure($rb->getErrorCode());\n}","tryCatchPattern":"try {\n    $catalogue = $loader->load($resource, $locale);\n} catch (InvalidResourceException $e) {\n    $logger->error('ICU resource load failed', ['resource' => $resource, 'msg' => $e->getMessage()]);\n    $catalogue = new MessageCatalogue($locale);\n}","preventionTips":["Build and verify .res bundles in CI before deployment","Add is_file/is_readable checks in the translation bootstrap","Keep ICU toolchain and runtime intl versions aligned","Log bundle paths at startup to catch misconfig early"],"tags":["intl","resource-bundle","translation","file-not-found"],"backgroundTag":"file-read-failed","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"}