You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/qute-reference.adoc
+37-12Lines changed: 37 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2459,7 +2459,25 @@ In the development mode, all files located in `src/main/resources/templates` are
2459
2459
The basic idea is that every message is potentially a very simple template.
2460
2460
In order to prevent type errors a message is defined as an annotated method of a *message bundle interface*.
2461
2461
Quarkus generates the *message bundle implementation* at build time.
2462
-
Subsequently, the bundles can be used at runtime:
2462
+
2463
+
.Message Bundle Interface Example
2464
+
[source,java]
2465
+
----
2466
+
import io.quarkus.qute.i18n.Message;
2467
+
import io.quarkus.qute.i18n.MessageBundle;
2468
+
2469
+
@MessageBundle <1>
2470
+
public interface AppMessages {
2471
+
2472
+
@Message("Hello {name}!") <2>
2473
+
String hello_name(String name); <3>
2474
+
}
2475
+
----
2476
+
<1> Denotes a message bundle interface. The bundle name is defaulted to `msg` and is used as a namespace in templates expressions, e.g. `{msg:hello_name}`.
2477
+
<2> Each method must be annotated with `@Message`. The value is a qute template. If no value is provided, then a corresponding value from a localized file is taken. If no such file exists an exception is thrown and the build fails.
2478
+
<3> The method parameters can be used in the template.
2479
+
2480
+
The message bundles can be used at runtime:
2463
2481
2464
2482
1. Directly in your code via `io.quarkus.qute.i18n.MessageBundles#get()`; e.g. `MessageBundles.get(AppMessages.class).hello_name("Lucie")`
2465
2483
2. Injected in your beans via `@Inject`; e.g. `@Inject AppMessages`
@@ -2475,26 +2493,33 @@ Subsequently, the bundles can be used at runtime:
2475
2493
<3> `Lucie` is the parameter of the message bundle interface method.
2476
2494
<4> It is also possible to obtain a localized message for a key resolved at runtime using a reserved key `message`. The validation is skipped in this case though.
2477
2495
2478
-
.Message Bundle Interface Example
2496
+
2497
+
==== Default Bundle Name
2498
+
2499
+
The bundle name is defaulted unless it's specified with `@MessageBundle#value()`.
2500
+
For a top-level class the `msg` value is used by default.
2501
+
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.
2502
+
2503
+
For example, the name of the following message bundle will be defaulted to `msg_Index`:
2504
+
2479
2505
[source,java]
2480
2506
----
2481
-
import io.quarkus.qute.i18n.Message;
2482
-
import io.quarkus.qute.i18n.MessageBundle;
2507
+
class Index {
2483
2508
2484
-
@MessageBundle <1>
2485
-
public interface AppMessages {
2509
+
@MessageBundle
2510
+
interface Bundle {
2486
2511
2487
-
@Message("Hello {name}!") <2>
2488
-
String hello_name(String name); <3>
2512
+
@Message("Hello {name}!")
2513
+
String hello(String name);
2514
+
}
2489
2515
}
2490
2516
----
2491
-
<1> Denotes a message bundle interface. The bundle name is defaulted to `msg` and is used as a namespace in templates expressions, e.g. `{msg:hello_name}`.
2492
-
<2> Each method must be annotated with `@Message`. The value is a qute template. If no value is provided, then a corresponding value from a localized file is taken. If no such file exists an exception is thrown and the build fails.
2493
-
<3> The method parameters can be used in the template.
2517
+
2518
+
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`.
2494
2519
2495
2520
==== Bundle Name and Message Keys
2496
2521
2497
-
Keys are used directly in templates.
2522
+
Message keys are used directly in templates.
2498
2523
The bundle name is used as a namespace in template expressions.
2499
2524
The `@MessageBundle` can be used to define the default strategy used to generate message keys from method names.
2500
2525
However, the `@Message` can override this strategy and even define a custom key.
Copy file name to clipboardExpand all lines: extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/LocalizedFileBundleLocaleMergeTest.java
Copy file name to clipboardExpand all lines: extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/LocalizedFileDefaultLocaleMergeTest.java
Copy file name to clipboardExpand all lines: extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/LocalizedFileResourceBundleNameTest.java
Copy file name to clipboardExpand all lines: extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleCustomDefaultLocaleTest.java
Copy file name to clipboardExpand all lines: extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleExpressionValidationTest.java
Copy file name to clipboardExpand all lines: extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/i18n/MessageBundleLogicalLineTest.java
0 commit comments