com.jn.langx.text.i18n.SimpleResourceBundleI18nMessageStorage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of langx-java Show documentation
Show all versions of langx-java Show documentation
Java lang extensions for java6+, a supplement to , replacement of a Guava, commons-lang.
Core utilities, Collection utilities, IO utilities, Cache, Configuration library ...
package com.jn.langx.text.i18n;
import com.jn.langx.annotation.NonNull;
import com.jn.langx.annotation.Nullable;
import com.jn.langx.util.Preconditions;
import com.jn.langx.util.Strings;
import java.util.Locale;
import java.util.ResourceBundle;
public class SimpleResourceBundleI18nMessageStorage extends AbstractResourceBundleI18nMessageStorage {
private ResourceBundle bundle;
public void setBundle(ResourceBundle bundle) {
Preconditions.checkNotNull(bundle);
this.bundle = bundle;
setLocale(bundle.getLocale());
}
@Override
protected String getMessageInternal(@Nullable final String basename, @Nullable final Locale locale, final @Nullable ClassLoader classLoader, @NonNull String key, Object... args) {
String message = ResourceBundles.getString(bundle, key, args);
if (Strings.isBlank(message) && getParent() != null) {
message = getParent().getMessage(locale, classLoader, key, args);
}
return message;
}
}