The issue is with the H5P module when Drupal is set to allow language overrides. Specifically this method.
If the language is set to English and user configuration form has Estonian as the language choice, then this will serve the newly loaded H5P libraries in Estonian, because the call is being made to h5peditor/...
instead of en/h5peditor/...
, which does not set the correct current language.
It seems that for paths that are not defined in the system, and this one is not among the defined routes, CacheableMetadata for current language is not included.
I would like to know if that is a bug (and should be reported) or a feature (this is how it functions). My guess would be that any internal path should include a language prefix, even when it is not defined in the system, but it's hard to be sure.
Update.
I suppose that the explanation for that behavior could be found in the documentation of Url::fromUserInput method, which clearly states:
If the path matches a Drupal route, then the URL generation will include Drupal's path processors (e.g., language-prefixing and aliasing). Otherwise, the URL generation will just append the passed-in path to Drupal's base path.
I only see one way to deal with that in a generally usable and meaningful way. Use the route for portal root, add a slash if it has a prefix instead of just a slash.
$baseUrl = Url::fromUri('internal:/')->toString();
$path = "some/path/that/is/not/a/route";
return $baseUrl === '/' ? "/{$path}"
: "{$baseUrl}/${$path}";
It might not be the best possible solution, but it should still get the job done and work in all possible cases. One could even create a function/method for that which would allow passing the options and maybe something else.