Why doesn't Spring use locale `en` when given `en_US`?
Related but not the same as this answer. I have
@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver ahlr = new AcceptHeaderLocaleResolver();
ahlr.setDefaultLocale(Locale.ENGLISH);
return ahlr;
}
And my browser is sending Accept-Language: en-US,en;q=0.9
. I have messages_en.properties
(but not messages.properties
). I get this error
javax.servlet.jsp.JspTagException: No message found under code 'title' for locale 'en_US'.
I know I can fix it by renaming messages_en.properties
to messages.properties
, but why doesn't Spring Boot find the en
locale when given en_US
?
I expect this to be a problem when someone has fr_FR
locale instead of just fr
. Must I really duplicate the locales for every single country?
How can I make Spring smarter to use the language if the specific country locale is not found?
Spring Boot 1.5.13, Spring Core 4.3.17
spring spring-boot spring-internationalization
add a comment |
Related but not the same as this answer. I have
@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver ahlr = new AcceptHeaderLocaleResolver();
ahlr.setDefaultLocale(Locale.ENGLISH);
return ahlr;
}
And my browser is sending Accept-Language: en-US,en;q=0.9
. I have messages_en.properties
(but not messages.properties
). I get this error
javax.servlet.jsp.JspTagException: No message found under code 'title' for locale 'en_US'.
I know I can fix it by renaming messages_en.properties
to messages.properties
, but why doesn't Spring Boot find the en
locale when given en_US
?
I expect this to be a problem when someone has fr_FR
locale instead of just fr
. Must I really duplicate the locales for every single country?
How can I make Spring smarter to use the language if the specific country locale is not found?
Spring Boot 1.5.13, Spring Core 4.3.17
spring spring-boot spring-internationalization
1
Because you need themessage.properties
(can be empty) to add a properMessageSource
. It will then use themessages_en.properties
. But themessages.properties
is required as the ultimate fallback (and the trigger for Spring Boot to enable a pre-configuredMessageSource
).
– M. Deinum
Nov 21 '18 at 18:03
I'm assuming you are using Spring Boot (as the tags state). Spring Boot uses the existence of the plain<basename>.properties
to add a pre-configuredMessageSource
. If that file isn't present, there is noMessageSource
and messages aren't resolved. Also theAcceptHeaderLocaleResolver
is already the default, instead of configuring it addingspring.mvc.locale=en
to theapplication.properties
is enough. So unless you aren't configuring things yourself or you aren't showing the full configuration.
– M. Deinum
Nov 21 '18 at 18:18
add a comment |
Related but not the same as this answer. I have
@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver ahlr = new AcceptHeaderLocaleResolver();
ahlr.setDefaultLocale(Locale.ENGLISH);
return ahlr;
}
And my browser is sending Accept-Language: en-US,en;q=0.9
. I have messages_en.properties
(but not messages.properties
). I get this error
javax.servlet.jsp.JspTagException: No message found under code 'title' for locale 'en_US'.
I know I can fix it by renaming messages_en.properties
to messages.properties
, but why doesn't Spring Boot find the en
locale when given en_US
?
I expect this to be a problem when someone has fr_FR
locale instead of just fr
. Must I really duplicate the locales for every single country?
How can I make Spring smarter to use the language if the specific country locale is not found?
Spring Boot 1.5.13, Spring Core 4.3.17
spring spring-boot spring-internationalization
Related but not the same as this answer. I have
@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver ahlr = new AcceptHeaderLocaleResolver();
ahlr.setDefaultLocale(Locale.ENGLISH);
return ahlr;
}
And my browser is sending Accept-Language: en-US,en;q=0.9
. I have messages_en.properties
(but not messages.properties
). I get this error
javax.servlet.jsp.JspTagException: No message found under code 'title' for locale 'en_US'.
I know I can fix it by renaming messages_en.properties
to messages.properties
, but why doesn't Spring Boot find the en
locale when given en_US
?
I expect this to be a problem when someone has fr_FR
locale instead of just fr
. Must I really duplicate the locales for every single country?
How can I make Spring smarter to use the language if the specific country locale is not found?
Spring Boot 1.5.13, Spring Core 4.3.17
spring spring-boot spring-internationalization
spring spring-boot spring-internationalization
asked Nov 21 '18 at 17:45
ChloeChloe
11k1982198
11k1982198
1
Because you need themessage.properties
(can be empty) to add a properMessageSource
. It will then use themessages_en.properties
. But themessages.properties
is required as the ultimate fallback (and the trigger for Spring Boot to enable a pre-configuredMessageSource
).
– M. Deinum
Nov 21 '18 at 18:03
I'm assuming you are using Spring Boot (as the tags state). Spring Boot uses the existence of the plain<basename>.properties
to add a pre-configuredMessageSource
. If that file isn't present, there is noMessageSource
and messages aren't resolved. Also theAcceptHeaderLocaleResolver
is already the default, instead of configuring it addingspring.mvc.locale=en
to theapplication.properties
is enough. So unless you aren't configuring things yourself or you aren't showing the full configuration.
– M. Deinum
Nov 21 '18 at 18:18
add a comment |
1
Because you need themessage.properties
(can be empty) to add a properMessageSource
. It will then use themessages_en.properties
. But themessages.properties
is required as the ultimate fallback (and the trigger for Spring Boot to enable a pre-configuredMessageSource
).
– M. Deinum
Nov 21 '18 at 18:03
I'm assuming you are using Spring Boot (as the tags state). Spring Boot uses the existence of the plain<basename>.properties
to add a pre-configuredMessageSource
. If that file isn't present, there is noMessageSource
and messages aren't resolved. Also theAcceptHeaderLocaleResolver
is already the default, instead of configuring it addingspring.mvc.locale=en
to theapplication.properties
is enough. So unless you aren't configuring things yourself or you aren't showing the full configuration.
– M. Deinum
Nov 21 '18 at 18:18
1
1
Because you need the
message.properties
(can be empty) to add a proper MessageSource
. It will then use the messages_en.properties
. But the messages.properties
is required as the ultimate fallback (and the trigger for Spring Boot to enable a pre-configured MessageSource
).– M. Deinum
Nov 21 '18 at 18:03
Because you need the
message.properties
(can be empty) to add a proper MessageSource
. It will then use the messages_en.properties
. But the messages.properties
is required as the ultimate fallback (and the trigger for Spring Boot to enable a pre-configured MessageSource
).– M. Deinum
Nov 21 '18 at 18:03
I'm assuming you are using Spring Boot (as the tags state). Spring Boot uses the existence of the plain
<basename>.properties
to add a pre-configured MessageSource
. If that file isn't present, there is no MessageSource
and messages aren't resolved. Also the AcceptHeaderLocaleResolver
is already the default, instead of configuring it adding spring.mvc.locale=en
to the application.properties
is enough. So unless you aren't configuring things yourself or you aren't showing the full configuration.– M. Deinum
Nov 21 '18 at 18:18
I'm assuming you are using Spring Boot (as the tags state). Spring Boot uses the existence of the plain
<basename>.properties
to add a pre-configured MessageSource
. If that file isn't present, there is no MessageSource
and messages aren't resolved. Also the AcceptHeaderLocaleResolver
is already the default, instead of configuring it adding spring.mvc.locale=en
to the application.properties
is enough. So unless you aren't configuring things yourself or you aren't showing the full configuration.– M. Deinum
Nov 21 '18 at 18:18
add a comment |
2 Answers
2
active
oldest
votes
For Spring Boot to auto configure a MessageSource
it checks the existence of the <basename>.properties
. If that exists a MessageSource
is configured, else nothing is configured and no messages will be resolved.
To fix add an empty <basename>.properties
to src/main/resource
to have the MessageSource
automatically configured.
add a comment |
Adding an empty messages.properties
fixed this issue as given in the above comment. Very strange and non-intuitive error message. If the comment is given as an answer, I will accept that.
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417837%2fwhy-doesnt-spring-use-locale-en-when-given-en-us%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
For Spring Boot to auto configure a MessageSource
it checks the existence of the <basename>.properties
. If that exists a MessageSource
is configured, else nothing is configured and no messages will be resolved.
To fix add an empty <basename>.properties
to src/main/resource
to have the MessageSource
automatically configured.
add a comment |
For Spring Boot to auto configure a MessageSource
it checks the existence of the <basename>.properties
. If that exists a MessageSource
is configured, else nothing is configured and no messages will be resolved.
To fix add an empty <basename>.properties
to src/main/resource
to have the MessageSource
automatically configured.
add a comment |
For Spring Boot to auto configure a MessageSource
it checks the existence of the <basename>.properties
. If that exists a MessageSource
is configured, else nothing is configured and no messages will be resolved.
To fix add an empty <basename>.properties
to src/main/resource
to have the MessageSource
automatically configured.
For Spring Boot to auto configure a MessageSource
it checks the existence of the <basename>.properties
. If that exists a MessageSource
is configured, else nothing is configured and no messages will be resolved.
To fix add an empty <basename>.properties
to src/main/resource
to have the MessageSource
automatically configured.
answered Nov 21 '18 at 18:45
M. DeinumM. Deinum
71.1k14142151
71.1k14142151
add a comment |
add a comment |
Adding an empty messages.properties
fixed this issue as given in the above comment. Very strange and non-intuitive error message. If the comment is given as an answer, I will accept that.
add a comment |
Adding an empty messages.properties
fixed this issue as given in the above comment. Very strange and non-intuitive error message. If the comment is given as an answer, I will accept that.
add a comment |
Adding an empty messages.properties
fixed this issue as given in the above comment. Very strange and non-intuitive error message. If the comment is given as an answer, I will accept that.
Adding an empty messages.properties
fixed this issue as given in the above comment. Very strange and non-intuitive error message. If the comment is given as an answer, I will accept that.
answered Nov 21 '18 at 18:23
ChloeChloe
11k1982198
11k1982198
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417837%2fwhy-doesnt-spring-use-locale-en-when-given-en-us%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Because you need the
message.properties
(can be empty) to add a properMessageSource
. It will then use themessages_en.properties
. But themessages.properties
is required as the ultimate fallback (and the trigger for Spring Boot to enable a pre-configuredMessageSource
).– M. Deinum
Nov 21 '18 at 18:03
I'm assuming you are using Spring Boot (as the tags state). Spring Boot uses the existence of the plain
<basename>.properties
to add a pre-configuredMessageSource
. If that file isn't present, there is noMessageSource
and messages aren't resolved. Also theAcceptHeaderLocaleResolver
is already the default, instead of configuring it addingspring.mvc.locale=en
to theapplication.properties
is enough. So unless you aren't configuring things yourself or you aren't showing the full configuration.– M. Deinum
Nov 21 '18 at 18:18