-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduces quarkus.locales=all #37106
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,16 @@ | ||
Locales (i18n) | ||
============== | ||
|
||
Native-image built application does not have all [locales](https://docs.oracle.com/javase/tutorial/i18n/locale/index.html) included by default as it | ||
unnecessarily inflates the executable size. | ||
|
||
One can configure native-image to [include locales](https://www.graalvm.org/latest/reference-manual/native-image/dynamic-features/Resources/#locales). This is mirrored in Quarkus configuration. | ||
|
||
All | ||
--- | ||
"All" test uses a special string "all" that internally translates as Locale.ROOT and is | ||
interpreted as "Include all locales". | ||
|
||
Some | ||
---- | ||
"Some" test uses a list of picked locales and verifies that only those are available. |
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,100 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-integration-test-locales</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>quarkus-integration-test-locales-all</artifactId> | ||
<name>Quarkus - Integration Tests - Locales - All</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive</artifactId> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-integration-test-locales-app</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/test/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<forkCount>1</forkCount> | ||
<reuseForks>false</reuseForks> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
26 changes: 26 additions & 0 deletions
26
integration-tests/locales/all/src/main/java/io/quarkus/locales/it/AllLocalesResource.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,26 @@ | ||
package io.quarkus.locales.it; | ||
|
||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
@Path("") | ||
public class AllLocalesResource extends LocalesResource { | ||
private static final Logger LOG = Logger.getLogger(AllLocalesResource.class); | ||
|
||
// @Pattern validation does nothing when placed in LocalesResource. | ||
@GET | ||
@Path("/hibernate-validator-test-validation-message-locale/{id}/") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Response validationMessageLocale( | ||
@Pattern(regexp = "A.*", message = "{pattern.message}") @PathParam("id") String id) { | ||
LOG.infof("Triggering test: id: %s", id); | ||
return Response.ok(id).build(); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
integration-tests/locales/all/src/test/java/io/quarkus/locales/it/LocalesIT.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,128 @@ | ||
package io.quarkus.locales.it; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.jboss.logging.Logger; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* A special case where we want to include all locales in our app. It must not matter which arbitrary locale we use, it must | ||
* work here. | ||
*/ | ||
@QuarkusIntegrationTest | ||
public class LocalesIT { | ||
|
||
private static final Logger LOG = Logger.getLogger(LocalesIT.class); | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
"en-US|en|United States", | ||
"de-DE|de|Deutschland", | ||
"de-AT|en|Austria", | ||
"de-DE|en|Germany", | ||
"zh-cmn-Hans-CN|cs|Čína", | ||
"zh-Hant-TW|cs|Tchaj-wan", | ||
"ja-JP-JP-#u-ca-japanese|sg|Zapöon" | ||
}, delimiter = '|') | ||
public void testCorrectLocales(String country, String language, String translation) { | ||
LOG.infof("Triggering test: Country: %s, Language: %s, Translation: %s", country, language, translation); | ||
RestAssured.given().when() | ||
.get(String.format("/locale/%s/%s", country, language)) | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is(translation)) | ||
.log().all(); | ||
} | ||
|
||
@Test | ||
public void testItalyIncluded() { | ||
RestAssured.given().when() | ||
.get("/locale/it-IT/it") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is("Italia")) | ||
.log().all(); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
"0,666|en-US|666.0", | ||
"0,666|cs-CZ|0.666", | ||
"0,666|fr-FR|0.666", | ||
"0.666|fr-FR|0.0" | ||
}, delimiter = '|') | ||
public void testNumbers(String number, String locale, String expected) { | ||
LOG.infof("Triggering test: Number: %s, Locale: %s, Expected result: %s", number, locale, expected); | ||
RestAssured.given().when() | ||
.param("number", number) | ||
.param("locale", locale) | ||
.get("/numbers") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(equalTo(expected)) | ||
.log().all(); | ||
} | ||
|
||
@Test | ||
public void languageRanges() { | ||
RestAssured.given().when() | ||
.param("range", "Accept-Language:iw,en-us;q=0.7,en;q=0.3") | ||
.get("/ranges") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is("[iw, he, en-us;q=0.7, en;q=0.3]")) | ||
.log().all(); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
// Ukrainian language preference is higher than Czech. | ||
"cs;q=0.7,uk;q=0.9|Привіт Світ!", | ||
// Czech language preference is higher than Ukrainian. | ||
"cs;q=1.0,uk;q=0.9|Ahoj světe!", | ||
// An unknown language preference, silent fallback to lingua franca. | ||
"jp;q=1.0|Hello world!" | ||
}, delimiter = '|') | ||
public void message(String acceptLanguage, String expectedMessage) { | ||
RestAssured.given().when() | ||
.header("Accept-Language", acceptLanguage) | ||
.get("/message") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is(expectedMessage)) | ||
.log().all(); | ||
} | ||
|
||
/** | ||
* @see integration-tests/hibernate-validator/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java | ||
*/ | ||
@ParameterizedTest | ||
@CsvSource(value = { | ||
// Croatian language preference is higher than Ukrainian. | ||
"en-US;q=0.25,hr-HR;q=0.9,fr-FR;q=0.5,uk-UA;q=0.1|Vrijednost ne zadovoljava uzorak", | ||
// Ukrainian language preference is higher than Croatian. | ||
"en-US;q=0.25,hr-HR;q=0.9,fr-FR;q=0.5,uk-UA;q=1.0|Значення не відповідає зразку", | ||
// An unknown language preference, silent fallback to lingua franca. | ||
"invalid string|Value is not in line with the pattern", | ||
// Croatian language preference is the highest. | ||
"en-US;q=0.25,hr-HR;q=1,fr-FR;q=0.5|Vrijednost ne zadovoljava uzorak", | ||
// Chinese language preference is the highest. | ||
"en-US;q=0.25,hr-HR;q=0.30,zh;q=0.9,fr-FR;q=0.50|數值不符合樣品", | ||
}, delimiter = '|') | ||
public void testValidationMessageLocale(String acceptLanguage, String expectedMessage) { | ||
RestAssured.given() | ||
.header("Accept-Language", acceptLanguage) | ||
.when() | ||
.get("/hibernate-validator-test-validation-message-locale/1") | ||
.then() | ||
.body(containsString(expectedMessage)); | ||
} | ||
} |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/AppMessages_cs.properties
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 @@ | ||
msg1=Ahoj světe! |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/AppMessages_en.properties
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 @@ | ||
msg1=Hello world! |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/AppMessages_uk.properties
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 @@ | ||
msg1=Привіт Світ! |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/ValidationMessages.properties
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 @@ | ||
pattern.message=Value is not in line with the pattern |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/ValidationMessages_hr_HR.properties
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 @@ | ||
pattern.message=Vrijednost ne zadovoljava uzorak |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/ValidationMessages_uk_UA.properties
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 @@ | ||
pattern.message=Значення не відповідає зразку |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/ValidationMessages_zh.properties
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 @@ | ||
pattern.message=數值不符合樣品 |
2 changes: 2 additions & 0 deletions
2
integration-tests/locales/all/src/test/resources/application.properties
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,2 @@ | ||
quarkus.locales=all | ||
quarkus.native.resources.includes=AppMessages_*.properties |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, what's the rationale of that? Can't we rely on the config being configured to
all
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gsmet It covers situation when user mis/configures something like:
quarkus.locales=fr,all,en-GB
as ROOT is what I use in place of "all".If you find it clumsy, I can redefine that, check config instead for string "all" and treat anything like the aforementioned configuration as an error in LocaleProcessor in core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And so there's no way for the locale to be defined as root by the user/app? Because if you use it as marker, we absolutely need to never be used by a user/app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gsmet https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#ROOT
That's what I was working with.
I.e. user would have to set empty string for the property quarkus.locales to be parsed as ROOT. Setting empty string is not allowed by our value converter:O.K., user can do that as I found out when I tried.
If you set:
It's converted to Locale.ROOT and that is interpreted as "all" , i.e. it results in building a native image with
-H:+IncludeAllLocales
included....and it is also interpreted as "include all" by the Hibernate validator, so the test still passes. It means these to settings are equivalent:
and
Do you think this is wrong?
If you run on a system that has no langpacks, which is a real possibility I encountered, your one and only working Locale is not ROOT though, it is ENGLISH IIRC. Lemme try...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we could live with it. I tried to use
LANG=C
and AFAICS, I end up with an English locale.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it all falls back to ENGLISH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e. tests fail due to this, but I already documented it here: https://github.com/quarkusio/quarkus/blob/main/integration-tests/locales/src/test/java/io/quarkus/locales/it/LocalesIT.java#L17