Rename method + remove dead code

This commit is contained in:
dotasek 2022-11-07 17:29:21 -05:00
parent 11c369ea09
commit 90f450ecb6
2 changed files with 3 additions and 28 deletions

View File

@ -74,17 +74,14 @@ public abstract class I18nBase {
* @return The formatted, internationalized, {@link String} * @return The formatted, internationalized, {@link String}
*/ */
public String formatMessage(String theMessage, Object... theMessageArguments) { public String formatMessage(String theMessage, Object... theMessageArguments) {
//if (isPluralKey(theMessage)) { return formatMessageForLocale(theMessage, theMessageArguments);
// throw new Error("I18n error: Plural Message called in non-plural mode");
//}
return formatMessagePlural(theMessage, theMessageArguments);
} }
protected String getPluralKey(Integer number, String baseKey) { protected String getPluralKey(Integer number, String baseKey) {
return baseKey + KEY_DELIMITER + pluralRules.select(number); return baseKey + KEY_DELIMITER + pluralRules.select(number);
} }
private String formatMessagePlural(String theMessage, Object... theMessageArguments) { private String formatMessageForLocale(String theMessage, Object... theMessageArguments) {
String message = theMessage; String message = theMessage;
if (messageExistsForLocale(theMessage, (theMessageArguments != null && theMessageArguments.length > 0))) { if (messageExistsForLocale(theMessage, (theMessageArguments != null && theMessageArguments.length > 0))) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) { if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
@ -112,9 +109,6 @@ public abstract class I18nBase {
*/ */
public String formatMessagePlural(Integer plural, String theMessage, Object... theMessageArguments) { public String formatMessagePlural(Integer plural, String theMessage, Object... theMessageArguments) {
//if (!isPluralKey(theMessage)) {
// throw new Error("I18n error: Non-plural Message called in plural mode");
//}
Object[] args = new Object[theMessageArguments.length+1]; Object[] args = new Object[theMessageArguments.length+1];
args[0] = plural; args[0] = plural;
for (int i = 0; i < theMessageArguments.length; i++) { for (int i = 0; i < theMessageArguments.length; i++) {
@ -122,11 +116,7 @@ public abstract class I18nBase {
} }
checkPluralRulesAreLoaded(); checkPluralRulesAreLoaded();
String pluralKey = getPluralKey(plural, theMessage); String pluralKey = getPluralKey(plural, theMessage);
return formatMessagePlural(pluralKey, args); return formatMessageForLocale(pluralKey, args);
}
private static boolean isPluralKey(String theMessage) {
return theMessage.endsWith(KEY_DELIMITER + PLURAL_SUFFIX);
} }
/** /**

View File

@ -119,20 +119,5 @@ class I18nBaseTest {
return Arrays.stream(items).anyMatch(inputStr::contains); return Arrays.stream(items).anyMatch(inputStr::contains);
} }
@Test
@Disabled
void pluralKeysCompleteAndValid() {
ResourceBundle loadedBundle = ResourceBundle.getBundle("Messages", Locale.GERMAN);
PluralRules pluralRules = PluralRules.forLocale(Locale.GERMANY);
for (String key : loadedBundle.keySet()) {
String[] keyComponent = key.split(I18nBase.KEY_DELIMITER);
assertFalse(keyComponent[keyComponent.length - 1].equalsIgnoreCase(I18nBase.PLURAL_SUFFIX), "Invalid use of PLURAL keyword for key: " + key);
if (keyComponent.length > 2
&& keyComponent[keyComponent.length - 2].equalsIgnoreCase(I18nBase.PLURAL_SUFFIX)) {
assertTrue(pluralRules.getKeywords().contains(keyComponent[keyComponent.length - 1]));
}
}
}
} }