PmLocalizeApi { public static String localizeOneOrMany(PmObject pm, String keybase, int number, Object... resArgs) { String key = keybase + (number > 1 ? "_many" : (number == 1 ? "_one" : "_none")); Object[] resArgsWithNumber = ArrayUtil.copyOf(resArgs, resArgs.length+1, 1); resArgsWithNumber[0] = number; String text = findLocalization(pm, key, resArgsWithNumber); return (text != null) ? text : localize(pm, keybase, resArgsWithNumber); }  static String findLocalization(PmObject pm, String key, Object... resStringArgs); static String localize(PmObject pm, String key, Object... resStringArgs); static String localizeEnumValue(PmObject pmCtxt, Enum<?> enumValue); static String localizeBooleanValue(PmAttr<?> pmAttr, Boolean value); static String localizeOneOrMany(PmObject pm, String keybase, int number, Object... resArgs); static void setResourceStringProvider(ResourceStringProvider resourceStringProvider); static String getOutputFormatString(PmAttr<?> pmAttr);  }
@Test public void testLocalizeOneOrMany() { assertEquals("If the provided number argument is 1, the resource key with the _one gets used.", "A single item", PmLocalizeApi.localizeOneOrMany(pmCtxt, "pmLocalizeApiTest.oneOrManyItems", 1)); assertEquals("If the provided number argument is greter than one, the resource key with the _many gets used." + "The number parameter is the first resource string parameter in this case.", "3 items", PmLocalizeApi.localizeOneOrMany(pmCtxt, "pmLocalizeApiTest.oneOrManyItems", 3)); }
@Test public void testLocalizeNoneOneOrMany() { assertEquals("If the provided number argument is zero, the resource key with the _none gets used.", "No item found", PmLocalizeApi.localizeOneOrMany(pmCtxt, "pmLocalizeApiTest.noneOneOrManyItems", 0)); assertEquals("If the provided number argument is 1, the resource key with the _one gets used.", "A single item", PmLocalizeApi.localizeOneOrMany(pmCtxt, "pmLocalizeApiTest.noneOneOrManyItems", 1)); assertEquals("If the provided number argument is greter than one, the resource key with the _many gets used." + "The number parameter is the first resource string parameter in this case.", "3 items", PmLocalizeApi.localizeOneOrMany(pmCtxt, "pmLocalizeApiTest.noneOneOrManyItems", 3)); }
@Test public void testLocalizeItemsWithNoneFallback() { assertEquals("If the provided number argument is zero, the resource key with the _none gets used.", "There is no item.", PmLocalizeApi.localizeOneOrMany(pmCtxt, "pmLocalizeApiTest.itemsWithNoneFallback", 0)); assertEquals("If the provided number argument is 1, the provided resource key will be used directly since there is no key with the _one postfix defined.", "1 items", PmLocalizeApi.localizeOneOrMany(pmCtxt, "pmLocalizeApiTest.itemsWithNoneFallback", 1)); assertEquals("If the provided number argument is greter than one, the provided resource key will be used directly since there is no key with the _many postfix defined.", "3 items", PmLocalizeApi.localizeOneOrMany(pmCtxt, "pmLocalizeApiTest.itemsWithNoneFallback", 3)); }