
com.github.aesteve.vertx.nubes.i18n.LocaleResolverRegistry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nubes Show documentation
Show all versions of nubes Show documentation
Provides an annotation layer on top of vertx-web.
The newest version!
package com.github.aesteve.vertx.nubes.i18n;
import io.vertx.ext.web.RoutingContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class LocaleResolverRegistry {
private final List resolvers;
private final List availableLocales;
private Locale defaultLocale;
public LocaleResolverRegistry(Locale loc) {
resolvers = new ArrayList<>();
availableLocales = new ArrayList<>();
availableLocales.add(loc);
}
public LocaleResolverRegistry(List availableLocales) {
resolvers = new ArrayList<>();
this.availableLocales = new ArrayList<>();
this.availableLocales.addAll(availableLocales);
}
public void addLocales(List locales) {
availableLocales.addAll(locales);
}
public Locale getDefaultLocale() {
return defaultLocale;
}
public void setDefaultLocale(Locale defaultLocale) {
this.defaultLocale = defaultLocale;
}
public void addResolver(LocaleResolver resolver) {
this.resolvers.add(resolver);
}
public void removeResolver(LocaleResolver resolver) {
this.resolvers.remove(resolver);
}
public List getAvailableLocales() {
return availableLocales;
}
public Locale resolve(RoutingContext context) {
for (LocaleResolver resolver : resolvers) {
Locale loc = resolver.resolve(context, availableLocales);
if (loc != null) {
return loc;
}
}
return defaultLocale;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy