Update ItemList.java

better handling of Empty CamelCased DisplayName
This commit is contained in:
Léa Gris 2019-12-26 02:04:01 +01:00 committed by GitHub
parent e5341f7cc7
commit cb147fb3da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -755,24 +755,20 @@ public enum ItemList implements IItemContainer {
ItemStack rStack = get(1, aReplacements); ItemStack rStack = get(1, aReplacements);
if (GT_Utility.isStackInvalid(rStack)) return NI; if (GT_Utility.isStackInvalid(rStack)) return NI;
// Construct a translation key from UnlocalizedName and sanitized DisplayName // CamelCase alphanumeric words from aDisplayName
StringBuilder tKeyBuilder = new StringBuilder(rStack.getUnlocalizedName()).append(".with."); StringBuilder tCamelCasedDisplayNameBuilder = new StringBuilder();
final String[] tDisplayNameWords = aDisplayName.split("\\W");
final String[] tWords = aDisplayName.split("\\W"); for (String tWord : tDisplayNameWords){
if (tWord.length() > 0) tCamelCasedDisplayNameBuilder.append(tWord.substring(0, 1).toUpperCase(Locale.US));
if (tWords.length > 0) { if (tWord.length() > 1) tCamelCasedDisplayNameBuilder.append(tWord.substring(1).toLowerCase(Locale.US));
// CamelCase alphanumeric words from aDisplayName }
for (String tWord : tWords){ if (tCamelCasedDisplayNameBuilder.length() == 0) {
if (tWord.length() > 0) tKeyBuilder.append(tWord.substring(0, 1).toUpperCase(Locale.US)); // CamelCased DisplayName is empty, so use hash of aDisplayName
if (tWord.length() > 1) tKeyBuilder.append(tWord.substring(1).toLowerCase(Locale.US)); tCamelCasedDisplayNameBuilder.append(((Long) (long)aDisplayName.hashCode()).toString());
}
} else {
// No alphanumeric words, so use hash of aDisplayName
tKeyBuilder.append(((Long) (long)aDisplayName.hashCode()).toString());
} }
tKeyBuilder.append(".name"); // Construct a translation key from UnlocalizedName and CamelCased DisplayName
final String tKey = tKeyBuilder.toString(); final String tKey = rStack.getUnlocalizedName() + ".with." + tCamelCasedDisplayNameBuilder.toString() + ".name";
rStack.setStackDisplayName(GT_LanguageManager.addStringLocalization(tKey, aDisplayName)); rStack.setStackDisplayName(GT_LanguageManager.addStringLocalization(tKey, aDisplayName));
return GT_Utility.copyAmount(aAmount, rStack); return GT_Utility.copyAmount(aAmount, rStack);