-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qute: Allow to specify default bundle file without language tag
- Loading branch information
1 parent
e6d8ca3
commit 506e3e2
Showing
5 changed files
with
235 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...yment/src/test/java/io/quarkus/qute/deployment/i18n/DefaultFileBundleLocaleMergeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package io.quarkus.qute.deployment.i18n; | ||
|
||
import static io.quarkus.qute.i18n.MessageBundle.DEFAULT_NAME; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.i18n.Localized; | ||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DefaultFileBundleLocaleMergeTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Messages.class, EnMessages.class, DeMessages.class) | ||
.addAsResource(new StringAsset("hello_world=Hi!"), "messages/msg_en.properties") | ||
.addAsResource(new StringAsset("farewell=Abschied\ngoodbye=Freilos"), "messages/msg_de.properties") | ||
.addAsResource(new StringAsset("goodbye=Mej se!\nfarewell=Sbohem!\nhello_world=Zdravim svete!"), | ||
"messages/msg.properties")) | ||
.overrideConfigKey("quarkus.default-locale", "cs"); | ||
|
||
@Localized("en") | ||
Messages enMessages; | ||
|
||
@Localized("de") | ||
Messages deMessages; | ||
|
||
@Inject | ||
Messages csMessages; | ||
|
||
/** | ||
* Default message template method is not overridden and message was set with {@link Message#value()}. | ||
*/ | ||
@Test | ||
void testDefaultFromAnnotationIsUsedAsFallback() { | ||
assertEquals("Nazdar!", enMessages.hello()); | ||
} | ||
|
||
/** | ||
* Default message template method is not overridden and message was set in default 'msg.properties' file. | ||
*/ | ||
@Test | ||
void testDefaultFromFileIsUsedAsFallback() { | ||
assertEquals("Mej se!", enMessages.goodbye()); | ||
} | ||
|
||
/** | ||
* Localized message template method is provided without {@link Message#value()} | ||
*/ | ||
@Test | ||
void testDefaultIsUsedAsFallback2() { | ||
assertEquals("Greetings!", enMessages.greetings()); | ||
} | ||
|
||
@Test | ||
void testLocalizedFileIsMerged() { | ||
assertEquals("Freilos", deMessages.goodbye()); | ||
} | ||
|
||
/** | ||
* Default message set with {@link Message#value()} has priority over message from 'msg.properties'. | ||
*/ | ||
@Test | ||
void testDefaultInterfaceHasPriority() { | ||
assertEquals("Ahoj svete!", csMessages.hello_world()); | ||
} | ||
|
||
@Test | ||
void testBothDefaultAndLocalizedFromFile() { | ||
assertEquals("Abschied", deMessages.farewell()); | ||
} | ||
|
||
@MessageBundle(DEFAULT_NAME) | ||
public interface Messages { | ||
|
||
@Message("Ahoj svete!") | ||
String hello_world(); | ||
|
||
@Message("Nazdar!") | ||
String hello(); | ||
|
||
String goodbye(); | ||
|
||
@Message("Greetings!") | ||
String greetings(); | ||
|
||
@Message | ||
String farewell(); | ||
} | ||
|
||
@Localized("en") | ||
public interface EnMessages extends Messages { | ||
|
||
@Message | ||
String greetings(); | ||
|
||
} | ||
|
||
@Localized("de") | ||
public interface DeMessages extends Messages { | ||
|
||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...yment/src/test/java/io/quarkus/qute/deployment/i18n/DefaultFileDefaultBundleNameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.qute.deployment.i18n; | ||
|
||
import static io.quarkus.qute.i18n.MessageBundle.DEFAULT_NAME; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.i18n.Localized; | ||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DefaultFileDefaultBundleNameTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Messages.class) | ||
.addAsResource(new StringAsset("goodbye=Mej se!\nfarewell=Sbohem!"), "messages/msg.properties")) | ||
.overrideConfigKey("quarkus.default-locale", "cs"); | ||
|
||
@Inject | ||
Messages csMessages1; | ||
|
||
@Localized("cs") | ||
Messages csMessages2; | ||
|
||
@Test | ||
void unannotatedMessageMethod() { | ||
assertEquals("Mej se!", csMessages1.goodbye()); | ||
} | ||
|
||
@Test | ||
void annotatedMessageMethod() { | ||
assertEquals("Sbohem!", csMessages2.farewell()); | ||
} | ||
|
||
@MessageBundle(DEFAULT_NAME) | ||
public interface Messages { | ||
|
||
String goodbye(); | ||
|
||
@Message | ||
String farewell(); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...ployment/src/test/java/io/quarkus/qute/deployment/i18n/DefaultFileDuplicateFoundTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.qute.deployment.i18n; | ||
|
||
import static io.quarkus.qute.i18n.MessageBundle.DEFAULT_NAME; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.deployment.MessageBundleException; | ||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DefaultFileDuplicateFoundTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addAsResource(new StringAsset("hi=Nazdar!"), "messages/msg.properties") | ||
.addAsResource(new StringAsset("hi=Ahoj!"), "messages/msg_cs.properties")) | ||
.overrideConfigKey("quarkus.default-locale", "cs") | ||
.assertException(t -> { | ||
Throwable e = t; | ||
MessageBundleException mbe = null; | ||
while (e != null) { | ||
if (e instanceof MessageBundleException) { | ||
mbe = (MessageBundleException) e; | ||
break; | ||
} | ||
e = e.getCause(); | ||
} | ||
assertNotNull(mbe); | ||
assertTrue(mbe.getMessage().contains("localized file already exists for locale [cs]"), mbe.getMessage()); | ||
assertTrue(mbe.getMessage().contains("msg_cs.properties"), mbe.getMessage()); | ||
assertTrue(mbe.getMessage().contains("msg.properties"), mbe.getMessage()); | ||
}); | ||
|
||
@Test | ||
public void testValidation() { | ||
fail(); | ||
} | ||
|
||
@MessageBundle(DEFAULT_NAME) | ||
public interface Messages { | ||
@Message | ||
String hi(); | ||
} | ||
|
||
} |