Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reference-manual/native-image/Resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ See also the [guide on assisted configuration of Java resources and other dynami
## Locales

It is also possible to specify which locales should be included in the image and what should be the default one.
For example, to switch the default locale to German and also include French and English, one can use the following hosted options.
For example, to switch the default locale to Swiss German and also include French and English, one can use the following hosted options.
```shell
native-image -H:DefaultLocale=de -H:IncludeLocales=fr,en
native-image -Duser.country=CH -Duser.language=de -H:IncludeLocales=fr,en
```
The locales are specified using [language tags](https://docs.oracle.com/javase/tutorial/i18n/locale/matching.html). All
locales can be included via ``-H:+IncludeAllLocales``, but please note that it increases the size of the resulting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ public abstract class LocalizationFeature implements Feature {
private final ForkJoinPool compressionPool = Options.LocalizationCompressInParallel.getValue() ? new ForkJoinPool(NativeImageOptions.NumberOfThreads.getValue()) : null;

/**
* The Locale that the native image is built for. Currently, switching the Locale at run time is
* not supported because the resource bundles are only included for one Locale. We use the
* Locale that is set for the image generator.
* The Locale that the native image is built for.
*/
protected Locale defaultLocale = Locale.getDefault();

Expand All @@ -154,7 +152,8 @@ public static class Options {
@Option(help = "Make all hosted charsets available at run time")//
public static final HostedOptionKey<Boolean> AddAllCharsets = new HostedOptionKey<>(false);

@Option(help = "Default locale of the image, by the default it is the same as the default locale of the image builder.", type = OptionType.User)//
@Option(help = "Default locale of the image, by the default it is the same as the default locale of the image builder.", type = OptionType.User, //
deprecated = true, deprecationMessage = "Please switch to using system properties such as -Duser.country=CH -Duser.language=de")//
public static final HostedOptionKey<String> DefaultLocale = new HostedOptionKey<>(Locale.getDefault().toLanguageTag());

@Option(help = "Default charset of the image, by the default it is the same as the default charset of the image builder.", type = OptionType.User)//
Expand Down Expand Up @@ -236,8 +235,10 @@ private static ResolvedJavaField findStaticField(ResolvedJavaType declaringClass
public void afterRegistration(AfterRegistrationAccess access) {
findClassByName = access::findClassByName;
allLocales = processLocalesOption();
defaultLocale = LocalizationSupport.parseLocaleFromTag(Options.DefaultLocale.getValue());
UserError.guarantee(defaultLocale != null, "Invalid default locale %s", Options.DefaultLocale.getValue());
if (Options.DefaultLocale.hasBeenSet()) {
defaultLocale = LocalizationSupport.parseLocaleFromTag(Options.DefaultLocale.getValue());
UserError.guarantee(defaultLocale != null, "Invalid default locale %s", Options.DefaultLocale.getValue());
}
try {
defaultCharset = Charset.forName(Options.DefaultCharset.getValue());
VMError.guarantee(defaultCharset.name().equals(Options.DefaultCharset.getValue()),
Expand Down