user3548223
user3548223

Reputation: 3

Grails: How to change the default validation error messages to other languages?

I'm trying to change the default validation messages to other languages like French, Japanese or Chinese but there's only one default language(English) I can see in my project(I'm using Groovy/Grails Tool Suite 3.6.0).

The fastest way to solve this question is to overwrite the default validation messages file(messages.properties) with other one such as messages_ja.properties.

I'm just wondering if there is another "dynamic" way to achieve this

Thank you

Upvotes: 0

Views: 278

Answers (2)

Hamila Mohamed Amine
Hamila Mohamed Amine

Reputation: 290

to change default langugage you can define something like this in your conf/spring/resources.groovy:

beans = { 
  localeResolver(SessionLocaleResolver) { 
        defaultLocale= Locale.JAPAN
        Locale.setDefault (Locale.JAPAN) 
  } 
} 

Upvotes: 0

Joshua Moore
Joshua Moore

Reputation: 24776

If your application as a different default language from English then the best approach is:

  1. Rename messages.properties to messages_en.properties
  2. Rename the messages_xx.properties to messages.properties (where xx is the new default)

This way English is still available for your application should you need to support it as well as your new default.

Upvotes: 2

Related Questions