diff --git a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleProcessor.java b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleProcessor.java index a78a3331d11d7..78be8027ee3d0 100644 --- a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleProcessor.java +++ b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleProcessor.java @@ -205,7 +205,7 @@ List processBundles(BeanArchiveIndexBuildItem beanArchiv Map localeToMergeCandidate = new HashMap<>(); for (Path messageFile : messageFiles) { String fileName = messageFile.getFileName().toString(); - if (fileName.startsWith(name)) { + if (bundleNameMatchesFileName(fileName, name)) { final String locale; int postfixIdx = fileName.indexOf('.'); if (postfixIdx == name.length()) { @@ -315,6 +315,30 @@ List processBundles(BeanArchiveIndexBuildItem beanArchiv return bundles; } + static boolean bundleNameMatchesFileName(String fileName, String name) { + int fileSeparatorIdx = fileName.indexOf('.'); + // Remove file extension if exists + if (fileSeparatorIdx > -1) { + fileName = fileName.substring(0, fileSeparatorIdx); + } + // Split the filename and the bundle name by underscores + String[] fileNameParts = fileName.split("_"); + String[] nameParts = name.split("_"); + + if (fileNameParts.length < nameParts.length) { + return false; + } + + // Compare each part of the filename with the corresponding part of the bundle name + for (int i = 0; i < nameParts.length; i++) { + if (!fileNameParts[i].equals(nameParts[i])) { + return false; + } + } + + return true; + } + @Record(value = STATIC_INIT) @BuildStep void initBundleContext(MessageBundleRecorder recorder, diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/MessageBundleProcessorTest.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/MessageBundleProcessorTest.java new file mode 100644 index 0000000000000..4850f984ef46c --- /dev/null +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/MessageBundleProcessorTest.java @@ -0,0 +1,26 @@ +package io.quarkus.qute.deployment; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class MessageBundleProcessorTest { + + @Test + void bundleNameMatchesFileName() { + assertTrue(MessageBundleProcessor.bundleNameMatchesFileName("messages.properties", "messages")); + assertTrue(MessageBundleProcessor.bundleNameMatchesFileName("started.properties", "started")); + assertTrue(MessageBundleProcessor.bundleNameMatchesFileName("startedValidation.properties", "startedValidation")); + assertTrue(MessageBundleProcessor.bundleNameMatchesFileName("EmailBundles_startedValidation.properties", + "EmailBundles_startedValidation")); + assertTrue(MessageBundleProcessor.bundleNameMatchesFileName("EmailBundles_startedValidation_pt_BR.properties", + "EmailBundles_startedValidation")); + + assertFalse(MessageBundleProcessor.bundleNameMatchesFileName("startedValidation.properties", "started")); + assertFalse(MessageBundleProcessor.bundleNameMatchesFileName("EmailBundles_startedValidation.properties", + "EmailBundles_started")); + assertFalse(MessageBundleProcessor.bundleNameMatchesFileName("EmailBundles_startedValidation_pt_BR.properties", + "EmailBundles_started")); + } +} diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/EmailBundles.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/EmailBundles.java new file mode 100644 index 0000000000000..2f7c89a8d0c19 --- /dev/null +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/EmailBundles.java @@ -0,0 +1,45 @@ +package io.quarkus.qute.deployment.i18n; + +import io.quarkus.qute.i18n.Message; +import io.quarkus.qute.i18n.MessageBundle; + +public class EmailBundles { + @MessageBundle + interface started { + @Message + String started(String id, String filename); + + @Message + String documentAccessUrl(String url); + + @Message + String nextNotification(); + + @Message + String signingProcessStart(String id, String filename); + + @Message + String subject(String customer, String filename); + + @Message + String signForValidation(); + } + + @MessageBundle + interface startedValidator { + @Message + String started(String id, String filename); + + @Message + String turnEmailWillBeSent(); + + @Message + String youMayAlreadyAccessDocument(); + + @Message + String subject(String customer, String filename); + + @Message + String signForValidation(); + } +} diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleNameCollisionTest.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleNameCollisionTest.java new file mode 100644 index 0000000000000..6c1d85c11b4c5 --- /dev/null +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleNameCollisionTest.java @@ -0,0 +1,38 @@ +package io.quarkus.qute.deployment.i18n; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.qute.Engine; +import io.quarkus.qute.i18n.MessageBundles; +import io.quarkus.test.QuarkusUnitTest; + +public class MessageBundleNameCollisionTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.default-locale", "en_US") + .withApplicationRoot((jar) -> jar + .addClasses(EmailBundles.class) + .addAsResource("messages/EmailBundles_started.properties") + .addAsResource("messages/EmailBundles_started_en.properties") + .addAsResource("messages/EmailBundles_startedValidator.properties") + .addAsResource("messages/EmailBundles_startedValidator_en.properties")); + + @Inject + Engine engine; + + @Test + public void testBundleMethodIsFound() { + EmailBundles.startedValidator startedValidator = MessageBundles.get(EmailBundles.startedValidator.class); + assertEquals("You will be notified with another email when it is your turn to sign.", + startedValidator.turnEmailWillBeSent()); + assertEquals("You will be notified with another email when it is your turn to sign.", + engine.parse("{EmailBundles_startedValidator:turnEmailWillBeSent()}").render()); + } + +} diff --git a/extensions/qute/deployment/src/test/resources/messages/EmailBundles_started.properties b/extensions/qute/deployment/src/test/resources/messages/EmailBundles_started.properties new file mode 100644 index 0000000000000..007c4b2517dc8 --- /dev/null +++ b/extensions/qute/deployment/src/test/resources/messages/EmailBundles_started.properties @@ -0,0 +1,6 @@ +started=In this process you will sign the document to validate it. +signingProcessStart=you have started a signing process {id} for document "{filename}". +nextNotification=You will be notified with another email when it is your signing turn. +documentAccessUrl=You may access the document in the following link: +subject=Signing process initiated by {customer} for file {filename}. +signForValidation=In this process you will sign the document to validate it. \ No newline at end of file diff --git a/extensions/qute/deployment/src/test/resources/messages/EmailBundles_startedValidator.properties b/extensions/qute/deployment/src/test/resources/messages/EmailBundles_startedValidator.properties new file mode 100644 index 0000000000000..88f05a121ad14 --- /dev/null +++ b/extensions/qute/deployment/src/test/resources/messages/EmailBundles_startedValidator.properties @@ -0,0 +1,5 @@ +signForValidation=In this process you will sign the document to validate it. +started=has started a signing process {id} for the document "{filename}". +subject=Signing process initiated by {customer} for file {filename}. +turnEmailWillBeSent=You will be notified with another email when it is your turn to sign. +youMayAlreadyAccessDocument=You can access the document at the following link: diff --git a/extensions/qute/deployment/src/test/resources/messages/EmailBundles_startedValidator_en.properties b/extensions/qute/deployment/src/test/resources/messages/EmailBundles_startedValidator_en.properties new file mode 100644 index 0000000000000..79d65ea85fb73 --- /dev/null +++ b/extensions/qute/deployment/src/test/resources/messages/EmailBundles_startedValidator_en.properties @@ -0,0 +1,5 @@ +signForValidation=In this process you will sign the document to validate it. +started=has started a signing process {id} for the document "{filename}". +subject=Signing process initiated by {customer} for file {filename}. +turnEmailWillBeSent=You will be notified with another email when it is your turn to sign. +youMayAlreadyAccessDocument=You can access the document at the following link: \ No newline at end of file diff --git a/extensions/qute/deployment/src/test/resources/messages/EmailBundles_started_en.properties b/extensions/qute/deployment/src/test/resources/messages/EmailBundles_started_en.properties new file mode 100644 index 0000000000000..007c4b2517dc8 --- /dev/null +++ b/extensions/qute/deployment/src/test/resources/messages/EmailBundles_started_en.properties @@ -0,0 +1,6 @@ +started=In this process you will sign the document to validate it. +signingProcessStart=you have started a signing process {id} for document "{filename}". +nextNotification=You will be notified with another email when it is your signing turn. +documentAccessUrl=You may access the document in the following link: +subject=Signing process initiated by {customer} for file {filename}. +signForValidation=In this process you will sign the document to validate it. \ No newline at end of file