I. Description
The following method implements a validator that reads a specified internationalized file.
1. Mymessages is a custom internationalized file, placed in the root directory of SRC
For example, there are mymessages_en_us.properties, mymessages_zh_cn.properties
2. Locale for the type of language you want to return
For example, the incoming new Locale ("en", "US") corresponds to the definition of the return mymessages_en_us;
Second, the validator code
public static Validator Getvalidatorbylocale (locale locale) { locale.setdefault (locale); Validator Validator = Validation.bydefaultprovider (). Configure () . Messageinterpolator ( New Resourcebundlemessageinterpolator (New Platformresourcebundlelocator ("Mymessages")) . Buildvalidatorfactory ( ). Getvalidator (); return validator; }
Hibernate validator Dynamic return internationalization tips