
ru.mynewtons.starter.oauth2.properties.UsersMessagesProperties Maven / Gradle / Ivy
The newest version!
package ru.mynewtons.starter.oauth2.properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Locale;
@Component
public class UsersMessagesProperties implements MessagesProperties {
@Autowired
@Qualifier("oauth2MessageSource")
private MessageSource messageSource;
@Autowired
private Locale locale;
@Override
public String getMessage(String code) {
try {
return messageSource.getMessage(code,
new String[]{LocaleContextHolder.getLocale().getDisplayCountry()},
LocaleContextHolder.getLocale());
} catch (NoSuchMessageException e) {
return messageSource.getMessage(code, new String[]{locale.getDisplayName(locale)}, locale);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy