is it possible to use someone's locale to serve different static content with springboot?
this is what my code currently does
@Configuration
@EnableWebMvc
public class MyConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/en-ca/**")
.addResourceLocations("/angular-output/en-CA");
registry
.addResourceHandler("/fr-ca/**")
.addResourceLocations("/angular-output/fr-CA");
}
}
but this method only allows me to setup mappings from a url-path to a file-path with no intermediate step to consider someone's locale to pick the file-path I want to use.
I wish I could do something like
@Configuration
@EnableWebMvc
public class MyConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/**").addResourceLocationSelector(
new ResourceLocationSelector() {
@Override
public string select() {
if (LocaleContextHolder.getLocale() == Locale.English) {
return "/angular-output/en-CA";
} else {
return "/angular-output/fr-CA";
}
}
}
)
}
}
I've had little luck trying to do such a seemingly basic thing with Spring Boot.