![JAR search and dependency download from the Maven repository](/logo.png)
net.yadaframework.core.YadaLocalePathLinkBuilder Maven / Gradle / Ivy
package net.yadaframework.core;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
import org.springframework.context.i18n.LocaleContextHolder;
import org.thymeleaf.context.IExpressionContext;
import org.thymeleaf.linkbuilder.StandardLinkBuilder;
/**
* Needed to create localized urls when using thymeleaf @{} syntax with context-relative paths like @{/somePath}.
* Also need to version the res folder because the yada:href dialect is not called when inlining with [[@{/somePath}]]
* @see YadaLinkBuilder
*/
@Deprecated // Use YadaLinkBuilder instead
public class YadaLocalePathLinkBuilder extends StandardLinkBuilder {
private Pattern nonLocalizedUrls;
public YadaLocalePathLinkBuilder(String notLocalizedResourcePattern) {
super();
nonLocalizedUrls = Pattern.compile(notLocalizedResourcePattern);
}
@Override
protected String computeContextPath(IExpressionContext context, String base, Map parameters) {
StringBuilder result = new StringBuilder(super.computeContextPath(context, base, parameters));
// Adding the current locale, but only if it is not a resource
boolean localizable = !nonLocalizedUrls.matcher(base).find();
if (localizable) {
Locale locale = LocaleContextHolder.getLocale();
String localeString = locale.getLanguage();
result.append("/").append(localeString);
}
return result.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy