From 3556e93043deef8818b7b644a7124bae6b0fded8 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Wed, 11 Mar 2026 14:23:00 +0200 Subject: [PATCH] Another attempt to fix localization resource bundles --- .../com/codename1/impl/javase/CSSWatcher.java | 8 +++-- .../com/codename1/maven/CompileCSSMojo.java | 29 ++++++++++++++----- .../codename1/maven/CompileCSSMojoTest.java | 26 +++++++++++++---- .../initializr/WebsiteThemeNativeImpl.java | 2 +- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/Ports/JavaSE/src/com/codename1/impl/javase/CSSWatcher.java b/Ports/JavaSE/src/com/codename1/impl/javase/CSSWatcher.java index c1e8266522..6141000822 100644 --- a/Ports/JavaSE/src/com/codename1/impl/javase/CSSWatcher.java +++ b/Ports/JavaSE/src/com/codename1/impl/javase/CSSWatcher.java @@ -151,9 +151,9 @@ File findLocalizationDirectory(File srcFile, String overrideInputs) { } /** - * Adds likely l10n locations derived from the CSS file and current working directory. + * Adds likely l10n/i18n locations derived from the CSS file and current working directory. *

We include relative common-module paths because JavaSE watch is often launched - * from the `javase` module while CSS/l10n are in `../common/src/main`.

+ * from the `javase` module while CSS/localization resources are in `../common/src/main`.

*/ void addLocalizationCandidates(File cssFile, List out) { if (cssFile == null) { @@ -164,13 +164,17 @@ void addLocalizationCandidates(File cssFile, List out) { File srcMainDirectory = cssDirectory.getParentFile(); if (srcMainDirectory != null) { out.add(new File(srcMainDirectory, "l10n")); + out.add(new File(srcMainDirectory, "i18n")); } } File workingDirectory = new File(System.getProperty("user.dir")); out.add(new File(workingDirectory, "l10n")); + out.add(new File(workingDirectory, "i18n")); out.add(new File(workingDirectory, "src/main/l10n")); + out.add(new File(workingDirectory, "src/main/i18n")); out.add(new File(workingDirectory, "../common/src/main/l10n")); + out.add(new File(workingDirectory, "../common/src/main/i18n")); } /** diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/CompileCSSMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/CompileCSSMojo.java index a8df113d4a..02cdb8f3db 100644 --- a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/CompileCSSMojo.java +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/CompileCSSMojo.java @@ -83,8 +83,8 @@ protected File findLocalizationDirectory() { if (parent == null) { continue; } - File localizationSibling = new File(parent, "l10n"); - if (hasLocalizationDirectory(localizationSibling)) { + File localizationSibling = findLocalizationSibling(parent); + if (localizationSibling != null) { return localizationSibling; } } @@ -92,12 +92,12 @@ protected File findLocalizationDirectory() { File cn1ProjectDir = getCN1ProjectDir(); if (cn1ProjectDir != null) { - File defaultLocalization = new File(cn1ProjectDir, path("src", "main", "l10n")); - if (hasLocalizationDirectory(defaultLocalization)) { - return defaultLocalization; + File sourceLocalization = findLocalizationSibling(new File(cn1ProjectDir, path("src", "main"))); + if (sourceLocalization != null) { + return sourceLocalization; } - File rootLocalization = new File(cn1ProjectDir, "l10n"); - if (hasLocalizationDirectory(rootLocalization)) { + File rootLocalization = findLocalizationSibling(cn1ProjectDir); + if (rootLocalization != null) { return rootLocalization; } } @@ -105,6 +105,21 @@ protected File findLocalizationDirectory() { return null; } + private File findLocalizationSibling(File parent) { + if (parent == null) { + return null; + } + File l10n = new File(parent, "l10n"); + if (hasLocalizationDirectory(l10n)) { + return l10n; + } + File i18n = new File(parent, "i18n"); + if (hasLocalizationDirectory(i18n)) { + return i18n; + } + return null; + } + /** * Treats an existing l10n directory as a valid localization source. *

This intentionally does not require `.properties` files up-front because diff --git a/maven/codenameone-maven-plugin/src/test/java/com/codename1/maven/CompileCSSMojoTest.java b/maven/codenameone-maven-plugin/src/test/java/com/codename1/maven/CompileCSSMojoTest.java index 5ad00b673e..2c67e79e04 100644 --- a/maven/codenameone-maven-plugin/src/test/java/com/codename1/maven/CompileCSSMojoTest.java +++ b/maven/codenameone-maven-plugin/src/test/java/com/codename1/maven/CompileCSSMojoTest.java @@ -26,7 +26,7 @@ class CompileCSSMojoTest { @Test void addsLocalizationDirectoryToDesignerInvocation(@TempDir Path tempDir) throws Exception { - Path projectDir = setupProject(tempDir, true); + Path projectDir = setupProject(tempDir, "l10n"); TestCompileCSSMojo mojo = createMojo(projectDir); mojo.executeImpl(); @@ -40,7 +40,7 @@ void addsLocalizationDirectoryToDesignerInvocation(@TempDir Path tempDir) throws @Test void skipsLocalizationArgumentWhenDirectoryMissing(@TempDir Path tempDir) throws Exception { - Path projectDir = setupProject(tempDir, false); + Path projectDir = setupProject(tempDir, null); TestCompileCSSMojo mojo = createMojo(projectDir); mojo.executeImpl(); @@ -51,7 +51,7 @@ void skipsLocalizationArgumentWhenDirectoryMissing(@TempDir Path tempDir) throws @Test void addsLocalizationArgumentWhenDirectoryIsEmpty(@TempDir Path tempDir) throws Exception { - Path projectDir = setupProject(tempDir, false); + Path projectDir = setupProject(tempDir, null); Files.createDirectories(projectDir.resolve("src/main/l10n")); TestCompileCSSMojo mojo = createMojo(projectDir); @@ -64,6 +64,20 @@ void addsLocalizationArgumentWhenDirectoryIsEmpty(@TempDir Path tempDir) throws assertEquals(projectDir.resolve("src/main/l10n").toFile().getAbsolutePath(), args.get(index + 1)); } + @Test + void addsI18nDirectoryToDesignerInvocation(@TempDir Path tempDir) throws Exception { + Path projectDir = setupProject(tempDir, "i18n"); + TestCompileCSSMojo mojo = createMojo(projectDir); + + mojo.executeImpl(); + + List args = mojo.getRecordingJava().getCommandLineArguments(); + assertTrue(args.contains("-l"), "Expected -l argument when i18n directory exists"); + int index = args.indexOf("-l"); + assertTrue(index >= 0 && index + 1 < args.size(), "Expected localization directory argument after -l"); + assertEquals(projectDir.resolve("src/main/i18n").toFile().getAbsolutePath(), args.get(index + 1)); + } + private TestCompileCSSMojo createMojo(Path projectDir) throws IOException { MavenProject mavenProject = new MavenProject(); mavenProject.setFile(projectDir.resolve("pom.xml").toFile()); @@ -87,7 +101,7 @@ private TestCompileCSSMojo createMojo(Path projectDir) throws IOException { return mojo; } - private Path setupProject(Path tempDir, boolean includeLocalization) throws IOException { + private Path setupProject(Path tempDir, String localizationDirName) throws IOException { Path projectDir = tempDir.resolve("project"); Files.createDirectories(projectDir); Files.createDirectories(projectDir.resolve("src/main/java")); @@ -107,8 +121,8 @@ private Path setupProject(Path tempDir, boolean includeLocalization) throws IOEx "" )); - if (includeLocalization) { - Path localizationDir = Files.createDirectories(projectDir.resolve("src/main/l10n")); + if (localizationDirName != null) { + Path localizationDir = Files.createDirectories(projectDir.resolve("src/main").resolve(localizationDirName)); Files.write(localizationDir.resolve("Messages.properties"), Arrays.asList("greeting=Hello")); } diff --git a/scripts/initializr/android/src/main/java/com/codename1/initializr/WebsiteThemeNativeImpl.java b/scripts/initializr/android/src/main/java/com/codename1/initializr/WebsiteThemeNativeImpl.java index de0d0b8e78..c5ad84f821 100644 --- a/scripts/initializr/android/src/main/java/com/codename1/initializr/WebsiteThemeNativeImpl.java +++ b/scripts/initializr/android/src/main/java/com/codename1/initializr/WebsiteThemeNativeImpl.java @@ -8,5 +8,5 @@ public boolean isDarkMode() { public boolean isSupported() { return false; } - + public void notifyUiReady() {} }