nosi.core.i18n.I18n Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of igrp-core Show documentation
Show all versions of igrp-core Show documentation
IGRP Framework is a powerful and highly customizable platform developed by the Operational Nucleus for the Information Society (NOSi) to create web applications, it provides out of box, several modules to make easy to create stand-alone, production-grade web applications: authentication and access-control, business processes automation, reporting, page builder with automatic code generation and incorporation of the Once-Only-Principle, written in Java. IGRP Framework WAR - Contains some keys resources that give UI to IGRP Framework and others supports files.
package nosi.core.i18n;
/**
* Marcel Iekiny
* Oct 27, 2017
*/
import java.util.ResourceBundle;
import gnu.gettext.GettextResource;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.text.MessageFormat;
public final class I18n implements Serializable {
private static final long serialVersionUID = 1788683894002641641L;
private ResourceBundle bundle;
public I18n(ResourceBundle bundle) {
this.bundle = bundle;
}
public String t(String text) {
if (bundle == null)
return text;
String result = GettextResource.gettext(bundle, StringUtils.stripAccents(text));
// If the result is the normalize text,
// return the result of text with special character
if (result.equals(StringUtils.stripAccents(text)))
return GettextResource.gettext(bundle, text);
return result;
}
public String t(String text, Object... objects) {
return MessageFormat.format(this.t(text), objects);
}
public String t(String text, String pluralText, long n) {
if (bundle == null)
return text;
return GettextResource.ngettext(bundle, text, pluralText, n);
}
public String t(String text, String pluralText, long n, Object... objects) {
return MessageFormat.format(this.t(text, pluralText, n), objects);
}
public ResourceBundle getBundle() {
return this.bundle;
}
}