New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[native-image] -H:IncludeResourceBundles only includes bundle for default locale #911
Comments
+1.
Can we express everything we put in H:IncludeResourceBundles in a json file? It does not see the case... |
Still broken in |
Hi and sorry to jump in. This is a major blocker for us in order to use native images. Pretty much every application we're designing is dealing with translations at some point. Is it going to be supported at some point? Or is this a feature native image won't ever support (so that we know if that's a "no-go" for building native images for every of our applications). Thank you. |
Since this doesn't seem to be getting fixed soon, let me update it with the workarounds we're using. I don't know how portable or reliable it will prove to be:
|
Alternatively you can use the following workaround using Features:
... then retrieve the required bundle at runtime like so:
Hope this helps. |
I really don't understand why this important limitation does not get more attention. |
@mipastgt Unfortunately this is not an easy limitation to lift. It requires a good bit of internal refactoring how resource bundles are handled in Native Image. In the current approach, all the loading happens at image build time. When doing that for all or a larger number of locales, then the image size will probably increase too much. So we probably need to switch to an approach where the locale data remains in (more compact) resources. |
Is there still no progress on this issue after nine months? For some applications this is a show stopper. |
This feature is set for 21.1 and will be implemented by @d-kozak. |
The native build of the CLI is fully functional, except for oracle/graal#911. Add graalvm_docker.ps1 for starting a GraalVM container on Windows and native-image configuration files created with java -agentlib:native-image-agent=config-output-dir=./native -jar target/zebra4j-0.7-SNAPSHOT-shaded.jar demo The CL also simplifies the implementation of AtHouse.TYPE#getAttributes and removes Demo from the public API.
This is still open on the 21.1 milestone, is this already resolved or should it be moved to another milestone? |
With native-image RC10,
-H:IncludeResourceBundles
includes only the bundle for the default locale at image build-time. This is useful only if just a single locale is needed for an application, and that locale is known at build-time - and that seems insufficient for most internationalization/localization use cases.As an example, take the following Java program:
And let
messages
be a property file backed resource bundle with two files:messages_en.properties
(msg=English message
), andmessages_ja.properties
(msg=Japanese message
). The example program is also available as a Gist.Running the code under the JVM produces the expected results -
ResourceBundle.getBundle(String, Locale)
returns the appropriate bundle for the given locale, and the default locale is determined from the host OS or properties at run-time.On the other hand, when using native-image,
-H:IncludeResourceBundles
only includes the bundle for the locale that is the default at image build-time, and the default locale is baked into the image. The replacement ofResourceBundle.getBundle(String, Locale)
ignores the locale argument, so the bundle corresponding to the default locale at build-time is returned for everygetBundle()
call.For this example, the locale for native-image was
en_US
:The default locale being baked into the image is irritating, but that could be worked around by writing application code that determines the correct locale at startup and calls
Locale.setDefault()
. But the current behavior of-H:IncludeResourceBundles
defeats the purpose of using resource bundles in most cases - it's no better than hardcoding messages for a single locale.At a minimum, I feel this should be clearly documented as a limitation where resource bundles are discussed (e.g. https://github.com/oracle/graal/blob/master/substratevm/RESOURCES.md).
But ideally, the example program would behave identically on the JVM and when compiled with native-image. I think that would mean that
com.oracle.svm.core.jdk.LocalizationSupport
would be enhanced to capture resource bundles for all locales (or at least, for a list of locales provided via an option at build-time - that would be sufficient for my needs). And SVM would ship a replacement for Locale.getDefault() that determines the correct locale at image run-time rather than image build-time.The text was updated successfully, but these errors were encountered: