add custom interpolator

This commit is contained in:
Krzysztof Majewski 2019-09-10 11:35:35 +02:00
parent d2d0b8537b
commit e48b29d58c
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package com.baeldung.interpolation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.validation.MessageInterpolator;
import java.util.Locale;
public class MyMessageInterpolator implements MessageInterpolator {
private static Logger logger = LoggerFactory.getLogger(MyMessageInterpolator.class);
private final MessageInterpolator defaultInterpolator;
public MyMessageInterpolator(MessageInterpolator interpolator) {
this.defaultInterpolator = interpolator;
}
@Override
public String interpolate(String messageTemplate, Context context) {
logger.debug("Selecting the language " + Locale.getDefault() + " for the error message.");
return defaultInterpolator.interpolate(messageTemplate, context, Locale.getDefault());
}
@Override
public String interpolate(String messageTemplate, Context context, Locale locale) {
return defaultInterpolator.interpolate(messageTemplate, context, locale);
}
}