Why doesn't Spring use locale `en` when given `en_US`?












0















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










share|improve this question


















  • 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











  • 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
















0















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










share|improve this question


















  • 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











  • 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














0












0








0








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 17:45









ChloeChloe

11k1982198




11k1982198








  • 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











  • 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














  • 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











  • 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








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












2 Answers
2






active

oldest

votes


















1














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.






share|improve this answer































    0














    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.






    share|improve this answer
























      Your Answer






      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      1














      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.






      share|improve this answer




























        1














        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.






        share|improve this answer


























          1












          1








          1







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 18:45









          M. DeinumM. Deinum

          71.1k14142151




          71.1k14142151

























              0














              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.






              share|improve this answer




























                0














                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.






                share|improve this answer


























                  0












                  0








                  0







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 18:23









                  ChloeChloe

                  11k1982198




                  11k1982198






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Guess what letter conforming each word

                      Port of Spain

                      Run scheduled task as local user group (not BUILTIN)