Skip to content

Instantly share code, notes, and snippets.

@linhvovn
Last active February 3, 2019 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linhvovn/31323e8b1c2794d935fe27756f60fa5e to your computer and use it in GitHub Desktop.
Save linhvovn/31323e8b1c2794d935fe27756f60fa5e to your computer and use it in GitHub Desktop.
@Component("messageSource")
public class DBMessageSource extends AbstractMessageSource {
@Autowired
private LanguageRepository languageRepository;
private static final String DEFAULT_LOCALE_CODE = "en";
@Override
protected MessageFormat resolveCode(String key, Locale locale) {
LanguageEntity message = languageRepository.findByKeyAndLocale(key,locale.getLanguage());
if (message == null) {
message = languageRepository.findByKeyAndLocale(key,DEFAULT_LOCALE_CODE);
}
return new MessageFormat(message.getContent(), locale);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment