1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
package tim.prune.function;
import tim.prune.I18nManager;
/**
* Class to build descriptions using singular and plural versions of a token
*/
public class Describer
{
private final String _singularToken;
private final String _pluralToken;
public Describer(String inSingularToken, String inPluralToken)
{
_singularToken = inSingularToken;
_pluralToken = inPluralToken;
}
public String getDescriptionWithNameOrCount(String inName, int inCount)
{
if (inCount == 1) {
return I18nManager.getText(_singularToken, inName == null ? "" : inName);
}
else if (inCount > 1) {
return I18nManager.getTextWithNumber(_pluralToken, inCount);
}
throw new IllegalArgumentException("Count should not be <= 0");
}
public String getDescriptionWithCount(int inCount)
{
if (inCount == 1) {
return I18nManager.getText(_singularToken);
}
else if (inCount > 1) {
return I18nManager.getTextWithNumber(_pluralToken, inCount);
}
throw new IllegalArgumentException("Count should not be <= 0");
}
public String getDescriptionWithNameOrNot(String inName)
{
// We use singular and plural here, but it means without name and with
if (inName == null || inName.isEmpty()) {
return I18nManager.getText(_singularToken);
}
return I18nManager.getText(_pluralToken, inName);
}
}
|