aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriouter <62897714+iouter@users.noreply.github.com>2022-10-13 00:54:21 +0800
committerGitHub <noreply@github.com>2022-10-12 18:54:21 +0200
commit0fab6334c54843e93398c495e0d00d72ca3aa67b (patch)
treeb619b40519eeff00b2db9dc97acd5aeaa9a45b51 /src
parentd42ad8f81bc79e87184a60c449a7a209c3a3681f (diff)
downloadGT5-Unofficial-0fab6334c54843e93398c495e0d00d72ca3aa67b.tar.gz
GT5-Unofficial-0fab6334c54843e93398c495e0d00d72ca3aa67b.tar.bz2
GT5-Unofficial-0fab6334c54843e93398c495e0d00d72ca3aa67b.zip
fix material localization (#395)
* fix material localization * spotlessApply
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java56
-rw-r--r--src/main/java/gtPlusPlus/core/material/Material.java11
2 files changed, 43 insertions, 24 deletions
diff --git a/src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java b/src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java
index 60685786f3..36f53640aa 100644
--- a/src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java
+++ b/src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java
@@ -41,6 +41,7 @@ public class BaseItemComponent extends Item {
public final Material componentMaterial;
public final String materialName;
public final String unlocalName;
+ public final String translatedMaterialName;
public final ComponentTypes componentType;
public final int componentColour;
public Object extraData;
@@ -52,6 +53,7 @@ public class BaseItemComponent extends Item {
this.componentMaterial = material;
this.unlocalName = "item" + componentType.COMPONENT_NAME + material.getUnlocalizedName();
this.materialName = material.getLocalizedName();
+ this.translatedMaterialName = material.getTranslatedName();
this.componentType = componentType;
this.setCreativeTab(AddToCreativeTab.tabMisc);
this.setUnlocalizedName(this.unlocalName);
@@ -76,6 +78,18 @@ public class BaseItemComponent extends Item {
}
}
registerComponent();
+
+ String aFormattedLangName = componentType.getName();
+ if (!aFormattedLangName.startsWith(" ")) {
+ if (aFormattedLangName.contains("@")) {
+ String[] aSplit = aFormattedLangName.split("@");
+ aFormattedLangName = aSplit[0] + " %material " + aSplit[1];
+ }
+ }
+ if (aFormattedLangName.equals(componentType.getName())) {
+ aFormattedLangName = "%material" + aFormattedLangName;
+ }
+ GT_LanguageManager.addStringLocalization("gtplusplus.item." + unlocalName + ".name", aFormattedLangName);
}
// For Cell Generation
@@ -93,6 +107,8 @@ public class BaseItemComponent extends Item {
this.componentMaterial = aTempMaterial;
this.unlocalName = "itemCell" + aFormattedNameForFluids;
this.materialName = localName;
+ this.translatedMaterialName =
+ GT_LanguageManager.addStringLocalization("gtplusplus.fluid." + this.unlocalName, this.materialName);
this.componentType = ComponentTypes.CELL;
this.setCreativeTab(AddToCreativeTab.tabMisc);
this.setUnlocalizedName(aFormattedNameForFluids);
@@ -106,6 +122,18 @@ public class BaseItemComponent extends Item {
ComponentTypes.CELL.getOreDictName() + Utils.sanitizeStringKeepBrackets(localName),
ItemUtils.getSimpleStack(this));
registerComponent();
+
+ String aFormattedLangName = componentType.getName();
+ if (!aFormattedLangName.startsWith(" ")) {
+ if (aFormattedLangName.contains("@")) {
+ String[] aSplit = aFormattedLangName.split("@");
+ aFormattedLangName = aSplit[0] + " %material " + aSplit[1];
+ }
+ }
+ if (aFormattedLangName.equals(componentType.getName())) {
+ aFormattedLangName = "%material" + aFormattedLangName;
+ }
+ GT_LanguageManager.addStringLocalization("gtplusplus.item." + unlocalName + ".name", aFormattedLangName);
}
public boolean registerComponent() {
@@ -181,30 +209,10 @@ public class BaseItemComponent extends Item {
@Override
public String getItemStackDisplayName(ItemStack stack) {
- if (componentMaterial == null) {
- String aFormattedLangName = componentType.getName();
- if (!aFormattedLangName.startsWith(" ")) {
- if (aFormattedLangName.contains("@")) {
- String[] aSplit = aFormattedLangName.split("@");
- aFormattedLangName = aSplit[0] + " " + getMaterialName() + " " + aSplit[1];
- }
- }
- if (aFormattedLangName.equals(componentType.getName())) {
- aFormattedLangName = getMaterialName() + aFormattedLangName;
- }
- return GT_LanguageManager.addStringLocalization(unlocalName, aFormattedLangName);
- }
- String aFormattedLangName = componentType.getName();
- if (!aFormattedLangName.startsWith(" ")) {
- if (aFormattedLangName.contains("@")) {
- String[] aSplit = aFormattedLangName.split("@");
- aFormattedLangName = aSplit[0] + " " + componentMaterial.getLocalizedName() + " " + aSplit[1];
- }
- }
- if (aFormattedLangName.equals(componentType.getName())) {
- aFormattedLangName = componentMaterial.getLocalizedName() + aFormattedLangName;
- }
- return GT_LanguageManager.addStringLocalization(unlocalName, aFormattedLangName);
+ return GT_LanguageManager.getTranslation("gtplusplus.item." + unlocalName + ".name")
+ .replace("%s", "%temp")
+ .replace("%material", translatedMaterialName)
+ .replace("%temp", "%s");
}
@SuppressWarnings({"unchecked", "rawtypes"})
diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java
index 7074bf5419..105110fe80 100644
--- a/src/main/java/gtPlusPlus/core/material/Material.java
+++ b/src/main/java/gtPlusPlus/core/material/Material.java
@@ -6,6 +6,7 @@ import static gtPlusPlus.core.util.math.MathUtils.safeCast_LongToInt;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.TextureSet;
+import gregtech.api.util.GT_LanguageManager;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes;
@@ -46,6 +47,7 @@ public class Material {
private String unlocalizedName;
private String localizedName;
+ private String translatedName;
private MaterialState materialState;
private TextureSet textureSet;
@@ -514,6 +516,8 @@ public class Material {
try {
this.unlocalizedName = Utils.sanitizeString(materialName);
this.localizedName = materialName;
+ this.translatedName =
+ GT_LanguageManager.addStringLocalization("gtplusplus.material." + unlocalizedName, localizedName);
mMaterialCache.put(getLocalizedName().toLowerCase(), this);
Logger.INFO("Stored " + getLocalizedName() + " to cache with key: "
+ getLocalizedName().toLowerCase());
@@ -1004,6 +1008,13 @@ public class Material {
return "ERROR.BAD.UNLOCALIZED.NAME";
}
+ public final String getTranslatedName() {
+ if (this.translatedName != null) {
+ return this.translatedName;
+ }
+ return "ERROR.BAD.TRANSLATED.NAME";
+ }
+
public final MaterialState getState() {
return this.materialState;
}