Skip to content
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

Qute I18N should support standard Java resource bundle filenames #30382

Closed
vagelis-savvas opened this issue Jan 15, 2023 · 5 comments · Fixed by #30391
Closed

Qute I18N should support standard Java resource bundle filenames #30382

vagelis-savvas opened this issue Jan 15, 2023 · 5 comments · Fixed by #30391
Labels
area/qute The template engine kind/enhancement New feature or request
Milestone

Comments

@vagelis-savvas
Copy link

Describe the bug

The I18N part of Qute does not allow someone to use the standard filename convention of Java resource bundle files, meaning we can't have e.g. msg.properties, msg_en.properties and msg_en_US.properties files. I believe it is related to the fact that quarkus.default-locale accepts values in IETF BCP 47 such as en-US, where a hyphen separates the locale components instead of an underscore.

Expected behavior

Qute should take into account standard Java resource bundle filenames, i.e. ones that separate the locale components with an underscore.

Actual behavior

Qute only considers resource bundle filenames where the locale components are separated with hyphens.

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@vagelis-savvas vagelis-savvas added the kind/bug Something isn't working label Jan 15, 2023
@quarkus-bot quarkus-bot bot added the area/qute The template engine label Jan 15, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 15, 2023

/cc @mkouba (qute)

@vagelis-savvas vagelis-savvas changed the title Qute I18N should support standard Java resource bundle files Qute I18N should support standard Java resource bundle filenames Jan 15, 2023
@gastaldi gastaldi added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Jan 15, 2023
@mkouba
Copy link
Contributor

mkouba commented Jan 16, 2023

I believe it is related to the fact that quarkus.default-locale accepts values in IETF BCP 47 such as en-US, where a hyphen separates the locale components instead of an underscore.

Yes, this is documented in https://quarkus.io/guides/qute-reference#localization: "The file name consists of the relevant bundle name (e.g. msg) and underscore followed by the locate language tag (IETF)". (note that there's a typo: locate -> language ;-)

@mkouba
Copy link
Contributor

mkouba commented Jan 16, 2023

@vagelis-savvas In fact, we don't require/validate the IETF language tag. I've just verified message_cs_CZ.properties in this draft PR #30391 and it works as expected. Of course, you need to use the same locale string when selecting the current locale, i.e. @Localized("cs_CZ") and templateInstance.setAttribute("locale", "cs_CZ").

What kind of error did you get in your application?

@vagelis-savvas
Copy link
Author

@mkouba Hello, I've created a MCVE here https://github.com/vagelis-savvas/code-with-qute-mcve which I bootstrapped from code.quarkus.io

I've only added an I18N 'greet' key: I use a @MessageBundle interface, some resource bundle files and edited the page.qute.html template to have a {msg:greet} instead of the hardcoded 'Hello'
If you mvn quarkus:dev you will see the errors.
If you rename the msg_en_US.properties and msg_en_GB.properties to msg_en-US.properties and msg_en-GB.properties it works.

mkouba added a commit to mkouba/quarkus that referenced this issue Jan 17, 2023
@mkouba
Copy link
Contributor

mkouba commented Jan 17, 2023

Hm, so the build fails because org.acme.AppMessages.greet() defines no message && MessageBundle#locale() for AppMessages is the default locale specified via the quarkus.default-locale (${user.language:en}-${user.country:} by default; e.g. en-US). As a result Qute attempts to find the msg_en-US.properties file. It works if you do @MessageBundle(locale = "en_US") public interface AppMessages {}.

In any case, we can just convert the locale info from the file to the expected language tag, i.e. replace _ with -; see #30391.

mkouba added a commit to mkouba/quarkus that referenced this issue Jan 17, 2023
@quarkus-bot quarkus-bot bot added this to the 2.17 - main milestone Jan 17, 2023
mfpc pushed a commit to mfpc/quarkus that referenced this issue Jan 19, 2023
ebullient pushed a commit to maxandersen/quarkus that referenced this issue Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/qute The template engine kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants