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
StringBuilder tKeyBuilder = new StringBuilder(rStack.getUnlocalizedName()).append(".with.");
final String[] tWords = aDisplayName.split("\\W");
if (tWords.length > 0) {
// CamelCase alphanumeric words from aDisplayName // CamelCase alphanumeric words from aDisplayName
for (String tWord : tWords){ StringBuilder tCamelCasedDisplayNameBuilder = new StringBuilder();
if (tWord.length() > 0) tKeyBuilder.append(tWord.substring(0, 1).toUpperCase(Locale.US)); final String[] tDisplayNameWords = aDisplayName.split("\\W");
if (tWord.length() > 1) tKeyBuilder.append(tWord.substring(1).toLowerCase(Locale.US)); for (String tWord : tDisplayNameWords){
if (tWord.length() > 0) tCamelCasedDisplayNameBuilder.append(tWord.substring(0, 1).toUpperCase(Locale.US));
if (tWord.length() > 1) tCamelCasedDisplayNameBuilder.append(tWord.substring(1).toLowerCase(Locale.US));
} }
} else { if (tCamelCasedDisplayNameBuilder.length() == 0) {
// No alphanumeric words, so use hash of aDisplayName // CamelCased DisplayName is empty, so use hash of aDisplayName
tKeyBuilder.append(((Long) (long)aDisplayName.hashCode()).toString()); tCamelCasedDisplayNameBuilder.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);