diff --git a/docs/src/main/asciidoc/qute-reference.adoc b/docs/src/main/asciidoc/qute-reference.adoc index 3c2db01f3403a..b865d1d336e8d 100644 --- a/docs/src/main/asciidoc/qute-reference.adoc +++ b/docs/src/main/asciidoc/qute-reference.adoc @@ -2498,24 +2498,26 @@ The message bundles can be used at runtime: The bundle name is defaulted unless it's specified with `@MessageBundle#value()`. For a top-level class the `msg` value is used by default. -For a nested class the name starts with `msg` followed by an underscore, followed by the simple names of all enclosing classes in the hierarchy (top-level class goes first) seperated by underscores. +For a nested class the name consists of the simple names of all enclosing classes in the hierarchy (top-level class goes first), followed by the simple name of the message bundle interface. +Names are separated by underscores. -For example, the name of the following message bundle will be defaulted to `msg_Index`: +For example, the name of the following message bundle will be defaulted to `Controller_index`: [source,java] ---- -class Index { +class Controller { @MessageBundle - interface Bundle { + interface index { @Message("Hello {name}!") - String hello(String name); + String hello(String name); <1> } } ---- +<1> This message could be used in a template via `{Controller_index:hello(name)}`. -NOTE: The bundle name is also used as a part of the name of a localized file, e.g. `msg_Index` in the `msg_Index_de.properties`. +NOTE: The bundle name is also used as a part of the name of a localized file, e.g. `Controller_index` in the `Controller_index_de.properties`. ==== Bundle Name and Message Keys 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 9ce486c302340..dc265e42d26c2 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 @@ -144,21 +144,19 @@ List processBundles(BeanArchiveIndexBuildItem beanArchiv } else { // The name starts with the DEFAULT_NAME followed by an underscore, followed by simple names of all // declaring classes in the hierarchy seperated by underscores - List enclosingNames = new ArrayList<>(); + List names = new ArrayList<>(); + names.add(DotNames.simpleName(bundleClass)); DotName enclosingName = bundleClass.enclosingClass(); while (enclosingName != null) { ClassInfo enclosingClass = index.getClassByName(enclosingName); if (enclosingClass != null) { - enclosingNames.add(DotNames.simpleName(enclosingClass)); + names.add(DotNames.simpleName(enclosingClass)); enclosingName = enclosingClass.nestingType() == NestingType.TOP_LEVEL ? null : enclosingClass.enclosingClass(); } } - enclosingNames.add(MessageBundle.DEFAULT_NAME); - // Class Bar declares nested class Foo and bundle Baz is declared as nested interface of Foo - // [Foo, Bar, msg] -> [msg, Bar, Foo] - Collections.reverse(enclosingNames); - name = String.join("_", enclosingNames); + Collections.reverse(names); + name = String.join("_", names); } LOG.debugf("Message bundle %s: name defaulted to %s", bundleClass, name); } diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/Controller.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/Controller.java new file mode 100644 index 0000000000000..b246b7ecb2f7e --- /dev/null +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/Controller.java @@ -0,0 +1,24 @@ +package io.quarkus.qute.deployment.i18n; + +import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateInstance; +import io.quarkus.qute.i18n.Message; +import io.quarkus.qute.i18n.MessageBundle; + +public class Controller { + + @CheckedTemplate + static class Templates { + + static native TemplateInstance index(String name); + + } + + @MessageBundle + public interface index { + + @Message("Hello {name}!") + String hello(String name); + } + +} diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleDefaultedNameTest.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleDefaultedNameTest.java index 1e490d355745c..7602b3b75eef3 100644 --- a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleDefaultedNameTest.java +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleDefaultedNameTest.java @@ -16,17 +16,17 @@ public class MessageBundleDefaultedNameTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar - .addClasses(Views.class) + .addClasses(Controller.class) .addAsResource(new StringAsset( - "{msg_Views_Index:hello(name)}"), - "templates/Index/index.html") - .addAsResource(new StringAsset("hello=Ahoj {name}!"), "messages/msg_Views_Index_cs.properties")); + "{Controller_index:hello(name)}"), + "templates/Controller/index.html") + .addAsResource(new StringAsset("hello=Ahoj {name}!"), "messages/Controller_index_cs.properties")); @Test public void testBundle() { assertEquals("Hello world!", - Views.Index.Templates.index("world").render()); - assertEquals("Ahoj svete!", Views.Index.Templates.index("svete") + Controller.Templates.index("world").render()); + assertEquals("Ahoj svete!", Controller.Templates.index("svete") .setAttribute(MessageBundles.ATTRIBUTE_LOCALE, Locale.forLanguageTag("cs")).render()); } diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleLocaleTest.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleLocaleTest.java index 0597581f7300f..2131cc87cac11 100644 --- a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleLocaleTest.java +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleLocaleTest.java @@ -23,7 +23,7 @@ public class MessageBundleLocaleTest { .withApplicationRoot((jar) -> jar .addClasses(Messages.class) .addAsResource(new StringAsset( - "{msg_MessageBundleLocaleTest:helloWorld}"), + "{MessageBundleLocaleTest_Messages:helloWorld}"), "templates/foo.html")); @Inject diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/Views.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/Views.java deleted file mode 100644 index 7d65642d44379..0000000000000 --- a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/Views.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.quarkus.qute.deployment.i18n; - -import io.quarkus.qute.CheckedTemplate; -import io.quarkus.qute.TemplateInstance; -import io.quarkus.qute.i18n.Message; -import io.quarkus.qute.i18n.MessageBundle; - -public class Views { - - public static class Index { - - @CheckedTemplate - static class Templates { - - static native TemplateInstance index(String name); - - } - - @MessageBundle - public interface Messages { - - @Message("Hello {name}!") - String hello(String name); - } - } - -} diff --git a/extensions/qute/runtime/src/main/java/io/quarkus/qute/i18n/MessageBundle.java b/extensions/qute/runtime/src/main/java/io/quarkus/qute/i18n/MessageBundle.java index c1d4e73e7ccf0..ae638cc4c77c9 100644 --- a/extensions/qute/runtime/src/main/java/io/quarkus/qute/i18n/MessageBundle.java +++ b/extensions/qute/runtime/src/main/java/io/quarkus/qute/i18n/MessageBundle.java @@ -43,18 +43,18 @@ *

* For a top-level class the {@value #DEFAULT_NAME} is used. *

- * For a nested class the name starts with the {@value #DEFAULT_NAME} followed by an undercore, followed by the simple names - * of all enclosing classes in the hierarchy (top-level class goes first) seperated by underscores. + * For a nested class the name consists of the simple names of all enclosing classes in the hierarchy (top-level class goes + * first), followed by the simple name of the message bundle interface. Names are separated by underscores. * - * For example, the name of the following message bundle will be defaulted to {@code msg_Index} and it could - * be used in a template via {msg_Index:hello(name)}: + * For example, the name of the following message bundle will be defaulted to {@code Controller_index} and it could + * be used in a template via {Controller_index:hello(name)}: * *

      * 
-     * class Index {
+     * class Controller {
      *
      *    @MessageBundle
-     *    interface Bundle {
+     *    interface index {
      *
      *       @Message("Hello {name}!")
      *       String hello(String name);