Skip to content

Commit 4eeb571

Browse files
authored
Merge pull request quarkusio#50829 from mkouba/issue-47585
Qute i18n: attempt to resolve ambiguity for multiple localized files
2 parents de71295 + 550074e commit 4eeb571

File tree

7 files changed

+287
-175
lines changed

7 files changed

+287
-175
lines changed

docs/src/main/asciidoc/qute-reference.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3042,7 +3042,14 @@ Message bundle files must be encoded in _UTF-8_.
30423042
The file name consists of the relevant bundle name (e.g. `msg`) and underscore followed by a language tag (IETF; e.g. `en-US`).
30433043
The language tag may be omitted, in which case the language tag of the default bundle locale is used.
30443044
For example, if bundle `msg` has default locale `en`, then `msg.properties` is going to be treated as `msg_en.properties`.
3045-
If both `msg.properties` and `msg_en.properties` are detected, an exception is thrown and build fails.
3045+
3046+
If there are multiple files for a specific locale then Qute attempts to resolve the ambiguity.
3047+
Localized files from the application root have higher priority and take precedence over localized files from dependencies.
3048+
If multiple files of the same priority exist, then the build fails.
3049+
For example, if the default bundle locale is `en` and the files `msg.properties` and `msg_en.properties` are found in the application root, then an exception is thrown and the build fails.
3050+
Or another example - if there are two dependencies and both contain the `msg_en.properties` file, then the build fails again.
3051+
On the other hand, if there is the `msg_en.properties` file in the application root and also the `msg_en.properties` file in a dependency, then messages from the application root take precedence and override the values from the dependency.
3052+
30463053
The file format is very simple: each line represents either a key/value pair with the equals sign used as a separator or a comment (line starts with `#`).
30473054
Blank lines are ignored.
30483055
Keys are _mapped to method names_ from the corresponding message bundle interface.

extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleBuildItem.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package io.quarkus.qute.deployment;
22

3-
import java.nio.file.Path;
3+
import java.util.List;
44
import java.util.Map;
55

66
import org.jboss.jandex.ClassInfo;
77

88
import io.quarkus.builder.item.MultiBuildItem;
9+
import io.quarkus.qute.deployment.MessageBundleProcessor.MessageFile;
910

1011
public final class MessageBundleBuildItem extends MultiBuildItem {
1112

1213
private final String name;
1314
private final ClassInfo defaultBundleInterface;
1415
private final Map<String, ClassInfo> localizedInterfaces;
15-
private final Map<String, Path> localizedFiles;
16-
private final Map<String, Path> mergeCandidates;
16+
private final Map<String, List<MessageFile>> localizedFiles;
17+
private final Map<String, List<MessageFile>> mergeCandidates;
1718
private final String defaultLocale;
1819

1920
public MessageBundleBuildItem(String name, ClassInfo defaultBundleInterface,
20-
Map<String, ClassInfo> localizedInterfaces, Map<String, Path> localizedFiles,
21-
Map<String, Path> mergeCandidates, String defaultLocale) {
21+
Map<String, ClassInfo> localizedInterfaces, Map<String, List<MessageFile>> localizedFiles,
22+
Map<String, List<MessageFile>> mergeCandidates, String defaultLocale) {
2223
this.name = name;
2324
this.defaultBundleInterface = defaultBundleInterface;
2425
this.localizedInterfaces = localizedInterfaces;
@@ -39,17 +40,15 @@ public Map<String, ClassInfo> getLocalizedInterfaces() {
3940
return localizedInterfaces;
4041
}
4142

42-
public Map<String, Path> getLocalizedFiles() {
43+
public Map<String, List<MessageFile>> getLocalizedFiles() {
4344
return localizedFiles;
4445
}
4546

4647
/**
4748
* Merge candidates are localized files used as a supplementary source of message templates
4849
* not specified by localized interfaces.
49-
*
50-
* @return locale -> localized file {@link Path}
5150
*/
52-
public Map<String, Path> getMergeCandidates() {
51+
public Map<String, List<MessageFile>> getMergeCandidates() {
5352
return mergeCandidates;
5453
}
5554

0 commit comments

Comments
 (0)