Last active
February 3, 2019 07:03
-
-
Save linhvovn/31323e8b1c2794d935fe27756f60fa5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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