Skip to main content

dawdler-server-plug-i18n

Module Introduction​

Provides injection of I18nOperator on the dawdler-server side.

1. Adding the Dependency to pom​

<groupId>club.dawdler</groupId>
<artifactId>dawdler-server-plug-i18n</artifactId>

2. Usage​

2.1 Using I18n​

Simply use the @I18nInjector annotation to mark a global variable as an I18nOperator-typed variable.

@Service
public class UserServiceImpl implements UserService {

@I18nInjector("messages")// messages is the base name of the configuration file, without the properties suffix
I18nOperator i18nOperator;

public User getUser(String userId) {
String message = i18nOperator.get("user.welcome");// use the i18nOperator object
System.out.println(message);
return null;
}

}

2.2 Using It in a Filter​

public class MyFilter implements DawdlerFilter {

@I18nInjector("messages")// messages is the base name of the configuration file, without the properties suffix
I18nOperator i18nOperator;

@Override
public void doFilter(RequestBean request, ResponseBean response, FilterChain chain) throws Exception {
String message = i18nOperator.get("filter.processing");// use the i18nOperator object
System.out.println(message);
chain.doFilter(request, response);
}
}

2.3 The Two Components That Support Injection on the dawdler Server Side​

  1. DawdlerFilter service filter

  2. Interface implementation classes annotated with @Service