【问题标题】:fallback messege file in spring boot is always "en"Spring Boot 中的后备消息文件始终为“en”
【发布时间】:2021-09-28 03:38:30
【问题描述】:

我按照https://www.baeldung.com/spring-boot-internationalization#localeresolver 中的说明配置了我的网络应用程序

将 Locale.ITALIAN 设置为 LocaleResolver bean 的默认语言环境。

我有两个消息文件:

  • 带有意大利语消息的message.properties
  • message_en.properties 带有英文消息

但是,messages_en.properties 中定义的标签(如果存在)。例如通过 lang=es 请求参数设置语言环境,显示英文消息。

如果我理解,预期的行为应该是如果 lang=en,则应该使用 message_en.properties,而对于所有其他语言,应该使用 message.properties 中的消息。

建议?

【问题讨论】:

    标签: spring-boot internationalization


    【解决方案1】:

    如果您使用最新版本的 Spring Boot(目前为 2.5.3),则该教程不是最新版本。例如,对于最新的 Spring,您必须进行额外但简单的配置来覆盖 LocaleResolver bean。

    根据您的实现,您可能需要在 application.properties 文件中添加 spring.messages.fallback-to-system-locale=false 行,或者如果您覆盖了“messageSource”bean,则必须在您自己的 bean 中设置 messageSource.setFallbackToSystemLocale(false);

    这样,应用程序应该可以按预期工作,除了 EN 之外的所有语言都使用 message.properties。

    【讨论】:

      猜你喜欢
      • 2021-04-02
      • 2016-12-24
      • 2017-10-26
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 2021-11-12
      • 2021-01-18
      相关资源
      最近更新 更多