
com.lyncode.choiceprops.PluralProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plural-property Show documentation
Show all versions of plural-property Show documentation
Plural Properties by Lyncode
The newest version!
package com.lyncode.choiceprops;
import com.lyncode.choiceprops.element.Expression;
import com.lyncode.choiceprops.element.ExpressionList;
import com.lyncode.choiceprops.parse.PluralPropertyParser;
import java.util.Map;
public class PluralProperty {
public static String translate (int choice, String message, Map replacements) throws PluralPropertyException {
ExpressionList expList = PluralPropertyParser.parse(message);
Expression selected = null;
for (Expression exp : expList) {
if (exp.in(choice)) {
selected = exp;
break;
}
}
if (selected == null)
throw new PluralPropertyException("Unable to find usable expression");
String result = selected.getExpression().trim();
for (Map.Entry entry : replacements.entrySet()) {
result = result.replace(entry.getKey(), entry.getValue().toString());
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy