From f8ab7fc1d75b7dea46312b633f5ade608a09a737 Mon Sep 17 00:00:00 2001 From: Konrad Neitzel Date: Sun, 22 Nov 2026 07:05:14 +0100 Subject: [PATCH] =?UTF-8?q?Plattformmen=C3=BCs=20und=20Lokalisierung=20f?= =?UTF-8?q?=C3=BCr=20JavaFX=20bereitstellen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fx/README.md | 1 + fx/docs/bars.md | 6 ++ fx/docs/i18n.md | 18 ++++ .../neitzel/fx/control/PlatformMenuBar.java | 26 +++++ .../de/neitzel/fx/docking/DockMessages.java | 19 +++- .../de/neitzel/fx/docking/DockingManager.java | 13 ++- .../docking/FloatingWindowConfiguration.java | 5 + .../java/de/neitzel/fx/i18n/LanguageMenu.java | 48 +++++++++ .../java/de/neitzel/fx/i18n/Localizer.java | 99 +++++++++++++++++++ .../java/de/neitzel/fx/i18n/Messages.java | 93 +++++++++++++++++ .../java/de/neitzel/fx/view/Components.java | 2 +- .../java/de/neitzel/fx/view/ViewLoader.java | 17 +++- .../main/resources/NeitzelLib-fx.properties | 44 +++++++++ .../resources/NeitzelLib-fx_de.properties | 43 ++++++++ .../resources/NeitzelLib-fx_en.properties | 44 +++++++++ .../neitzel/fx/view/FloatDockablesTest.java | 11 ++- .../de/neitzel/fx/view/LocalizerTest.java | 52 ++++++++++ .../resources/LocalizerTestApp_de.properties | 1 + .../LocalizerTestApp_de_CH.properties | 1 + .../resources/LocalizerTestApp_en.properties | 1 + .../resources/LocalizerTestLib_de.properties | 2 + 21 files changed, 536 insertions(+), 10 deletions(-) create mode 100644 fx/docs/i18n.md create mode 100644 fx/src/main/java/de/neitzel/fx/control/PlatformMenuBar.java create mode 100644 fx/src/main/java/de/neitzel/fx/i18n/LanguageMenu.java create mode 100644 fx/src/main/java/de/neitzel/fx/i18n/Localizer.java create mode 100644 fx/src/main/java/de/neitzel/fx/i18n/Messages.java create mode 100644 fx/src/main/resources/NeitzelLib-fx.properties create mode 100644 fx/src/main/resources/NeitzelLib-fx_de.properties create mode 100644 fx/src/main/resources/NeitzelLib-fx_en.properties create mode 100644 fx/src/test/java/de/neitzel/fx/view/LocalizerTest.java create mode 100644 fx/src/test/resources/LocalizerTestApp_de.properties create mode 100644 fx/src/test/resources/LocalizerTestApp_de_CH.properties create mode 100644 fx/src/test/resources/LocalizerTestApp_en.properties create mode 100644 fx/src/test/resources/LocalizerTestLib_de.properties diff --git a/fx/README.md b/fx/README.md index 795544a..d5317e3 100644 --- a/fx/README.md +++ b/fx/README.md @@ -2,6 +2,7 @@ ## Documentation map +- [Message catalogs, FXML localization and language changes](docs/i18n.md). - [FXML support for every public control](docs/fxml-controls.md). - [Build a complete application from scratch](docs/quick-start.md). diff --git a/fx/docs/bars.md b/fx/docs/bars.md index 70cfba1..b47dd1f 100644 --- a/fx/docs/bars.md +++ b/fx/docs/bars.md @@ -98,3 +98,9 @@ required. The launch class is ordinary Java and delegates to the Application. The [MVVM docking editor](../../fx-example/docs/docking-mvvm.md) demonstrates Dockable-owned bars and optional MVVM bindings alongside a plain JavaFX editor. The standalone controls also support ordinary JavaFX property bindings. + +## Window menus + +Use `PlatformMenuBar.create(file, quit, view)` from `de.neitzel.fx.control` to build a window's JavaFX menu bar. Supply fresh menus and a localized Quit item with its action already set. Place the result at the top of the scene. On macOS the native menu bar follows the focused stage and supplies the Quit command. On other platforms the file menu includes the supplied Quit item. With docking, route its action to `manager.requestMainWindowClose()`. + +For floating windows, set `FloatingWindowConfiguration.setMenuBarFactory(...)` in the floating window customizer. The factory receives the new window before it is shown. Use that window as the owner for dialogs launched by its menu. diff --git a/fx/docs/i18n.md b/fx/docs/i18n.md new file mode 100644 index 0000000..ae6c2d0 --- /dev/null +++ b/fx/docs/i18n.md @@ -0,0 +1,18 @@ +# Message catalogs for Java and FXML + +Create one Localizer per application. The initial locale can be null to use the JVM display locale. The second argument specifies the fallback language. Register the service with the same ApplicationContext used by ViewLoader. + +```java +var language = new Localizer(initialLocale, Locale.ENGLISH, + new Localizer.Catalog(MyApp.class, "MyApp", "org.example.myapp"), + LanguageMenu.CATALOG); +context.addSingleton(Localizer.class, language); +var texts = language.forClass(AccountController.class); +label.setText(texts.text("account.saved", accountName)); +``` + +Catalogs are UTF-8 properties files. For each key the search tries the requested locale's variants (for example de-CH before de), then variants of the fallback locale, then files without a language suffix. Each pass visits the view catalog beside its FXML, the controller's class catalog, package Messages catalogs up to the configured root, the named application catalog and the named library catalogs in registration order. For example, use Account_de.properties beside Account.fxml and MyApp_de.properties at the application resource root. Missing keys display as ⟦key⟧ and log once per locale and catalog context. Java calls with arguments use MessageFormat patterns. + +ViewLoader supplies the same Messages bundle to the FXMLLoader and the controller. Use `