I try to translate a LocalDateTime to the current used language like shown in this answer: https://stackoverflow.com/a/51843932
Running the program in Eclipse works as intended, but when it gets deployed with maven and jlink it falls back to english.
I assume I am missing a module to be required? Its a JDK17 modularized application.
I tried:
Locale loc = new Locale("de", "DE");
Locale.setDefault(loc);
lblDateTime.setText(LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("EEEE, dd. MMMM yyyy - HH:mm:ss");
lblDateTime.setText(LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("EEEE, dd. MMMM yyyy - HH:mm:ss", Locale.GERMAN);
lblDateTime.setText(LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("EEEE, dd. MMMM yyyy - HH:mm:ss").localizedBy(Locale.GERMAN);
Result in Eclipse in all 3 cases:
The module info:
module [name] {
[...]
requires transitive javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
requires org.apache.logging.log4j.core;
requires javafx.base;
requires org.controlsfx.controls;
requires java.base;
requires java.desktop;
}
Update 1:
The result of System.getProperty("java.locale.providers")
in both cases is null
.
Update 2:
Adding requires jdk.localedata;
to the module-info.java
solved the issue. See accepted answer.