It's about time we sorted out all these translations

This commit is contained in:
Electroblob77
2020-05-24 23:57:46 +01:00
parent d9f7d94115
commit 3e0dbb9755
12 changed files with 66 additions and 51 deletions
@@ -105,6 +105,29 @@ public class CommonProxy {
return ((ItemSpectralBow)WizardryItems.spectral_bow).getDefaultDurabilityForDisplay(stack);
}
/**
* Translates the given key with no specified style. Client-side only; on the server this simply returns
* the given translation key. Useful whenever translation from common classes is required, e.g. item tooltips.
* @param key The unlocalised name to be translated.
* @param args The format arguments to pass into the translation, if any.
* @return The resulting translated text.
*/
public String translate(String key, Object... args){
return translate(key, new Style(), args);
}
/**
* Translates the given key and formats it with the given style. Client-side only; on the server this simply returns
* the given translation key. Useful whenever translation from common classes is required, e.g. item tooltips.
* @param key The unlocalised name to be translated.
* @param style The {@link Style} to use for the displayed text.
* @param args The format arguments to pass into the translation, if any.
* @return The resulting translated text.
*/
public String translate(String key, Style style, Object... args){
return key;
}
/** Like {@link CommonProxy#addMultiLineDescription(List, String, Style, Object...)}, but style defaults to light grey. */
public void addMultiLineDescription(List<String> tooltip, String key, Object... args){
this.addMultiLineDescription(tooltip, key, new Style().setColor(TextFormatting.GRAY), args);
@@ -330,10 +330,14 @@ public class ClientProxy extends CommonProxy {
return super.getConjuredBowDurability(stack);
}
@Override
public String translate(String key, Style style, Object... args){
return style.getFormattingCode() + I18n.format(key, args);
}
@Override
public void addMultiLineDescription(List<String> tooltip, String key, Style style, Object... args){
String description = style.getFormattingCode() + I18n.format(key, args);
tooltip.addAll(Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(description, TOOLTIP_WRAP_WIDTH));
tooltip.addAll(Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(translate(key, style, args), TOOLTIP_WRAP_WIDTH));
}
// SECTION Particles
@@ -7,8 +7,6 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public enum Element implements IStringSerializable {
@@ -52,9 +50,8 @@ public enum Element implements IStringSerializable {
}
/** Returns the translated display name of this element, without formatting. */
@SideOnly(Side.CLIENT)
public String getDisplayName(){
return net.minecraft.client.resources.I18n.format("element." + getName());
return Wizardry.proxy.translate("element." + getName());
}
/** Returns the {@link Style} object representing the colour of this element. */
@@ -1,5 +1,6 @@
package electroblob.wizardry.constants;
import electroblob.wizardry.Wizardry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -37,6 +38,6 @@ public enum SpellType {
@SideOnly(Side.CLIENT)
public String getDisplayName(){
return net.minecraft.client.resources.I18n.format("spelltype." + unlocalisedName);
return Wizardry.proxy.translate("spelltype." + unlocalisedName);
}
}
@@ -1,11 +1,10 @@
package electroblob.wizardry.constants;
import electroblob.wizardry.Wizardry;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Random;
@@ -53,9 +52,9 @@ public enum Tier {
throw new IllegalArgumentException("No such tier with unlocalised name: " + name);
}
@SideOnly(Side.CLIENT)
/** Returns the translated display name of this tier, without formatting. */
public String getDisplayName(){
return net.minecraft.client.resources.I18n.format("tier." + unlocalisedName);
return Wizardry.proxy.translate("tier." + unlocalisedName);
}
/**
@@ -66,9 +65,9 @@ public enum Tier {
return new TextComponentTranslation("tier." + unlocalisedName);
}
@SideOnly(Side.CLIENT)
/** Returns the translated display name of this tier, with formatting. */
public String getDisplayNameWithFormatting(){
return this.getFormattingCode() + net.minecraft.client.resources.I18n.format("tier." + unlocalisedName);
return Wizardry.proxy.translate("tier." + unlocalisedName, this.colour);
}
/**
@@ -32,7 +32,9 @@ import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
@@ -305,9 +307,9 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem,
EntityPlayer player = net.minecraft.client.Minecraft.getMinecraft().player;
if (player == null) { return; }
// +0.5f is necessary due to the error in the way floats are calculated.
if(element != null) text.add("\u00A78" + net.minecraft.client.resources.I18n.format("item." + Wizardry.MODID + ":wand.buff",
(int)((tier.level + 1) * Constants.POTENCY_INCREASE_PER_TIER * 100 + 0.5f) + "%",
element.getDisplayName()));
if(element != null) text.add(Wizardry.proxy.translate("item." + Wizardry.MODID + ":wand.buff",
new Style().setColor(TextFormatting.DARK_GRAY),
(int)((tier.level + 1) * Constants.POTENCY_INCREASE_PER_TIER * 100 + 0.5f), element.getDisplayName()));
Spell spell = WandHelper.getCurrentSpell(stack);
@@ -317,22 +319,16 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem,
discovered = false;
}
text.add("\u00A77" + net.minecraft.client.resources.I18n.format("item." + Wizardry.MODID + ":wand.spell",
discovered ? "\u00A77" + spell.getDisplayNameWithFormatting()
: "#\u00A79" + SpellGlyphData.getGlyphName(spell, player.world)));
text.add(Wizardry.proxy.translate("item." + Wizardry.MODID + ":wand.spell", new Style().setColor(TextFormatting.GRAY),
discovered ? spell.getDisplayNameWithFormatting() : "#" + TextFormatting.BLUE + SpellGlyphData.getGlyphName(spell, player.world)));
if(advanced.isAdvanced()){
// Advanced tooltips for debugging
text.add("\u00A79" + net.minecraft.client.resources.I18n.format("item." + Wizardry.MODID + ":wand.mana",
text.add(Wizardry.proxy.translate("item." + Wizardry.MODID + ":wand.mana", new Style().setColor(TextFormatting.BLUE),
this.getMana(stack), this.getManaCapacity(stack)));
text.add("\u00A77" + net.minecraft.client.resources.I18n.format("item." + Wizardry.MODID + ":wand.progression",
text.add(Wizardry.proxy.translate("item." + Wizardry.MODID + ":wand.progression", new Style().setColor(TextFormatting.GRAY),
WandHelper.getProgression(stack), this.tier.level < Tier.MASTER.level ? Tier.values()[tier.ordinal() + 1].progression : 0));
// }else{
//
// ChargeStatus status = ChargeStatus.getChargeStatus(stack);
// text.add(status.getFormattingCode() + status.getDisplayName());
}
}
@@ -28,6 +28,8 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.fml.common.Mod;
@@ -93,19 +95,14 @@ public class ItemWizardArmour extends ItemArmor implements IWorkbenchItem, IMana
public void addInformation(ItemStack stack, World world, List<String> tooltip, net.minecraft.client.util.ITooltipFlag advanced){
if(stack.hasTagCompound() && stack.getTagCompound().getBoolean("legendary"))
tooltip.add("\u00A7d" + net.minecraft.client.resources.I18n.format("item." + Wizardry.MODID + ":wizard_armour.legendary"));
tooltip.add(Wizardry.proxy.translate("item." + Wizardry.MODID + ":wizard_armour.legendary",
new Style().setColor(TextFormatting.LIGHT_PURPLE)));
if(element != null){
tooltip.add("\u00A78" + net.minecraft.client.resources.I18n.format("item." + Wizardry.MODID + ":wizard_armour.buff",
(int)(Constants.COST_REDUCTION_PER_ARMOUR * 100) + "%", element.getDisplayName()));
tooltip.add(Wizardry.proxy.translate("item." + Wizardry.MODID + ":wizard_armour.buff",
new Style().setColor(TextFormatting.DARK_GRAY),
(int)(Constants.COST_REDUCTION_PER_ARMOUR * 100), element.getDisplayName()));
}
// tooltip.add("\u00A79" + net.minecraft.client.resources.I18n.format("item." + Wizardry.MODID + ":wizard_armour.mana",
// (this.getMaxDamage(stack) - this.getDamage(stack)), this.getMaxDamage(stack)));
// ChargeStatus status = ChargeStatus.getChargeStatus(stack);
//
// tooltip.add(status.getFormattingCode() + status.getDisplayName());
}
@Override
@@ -9,6 +9,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import javax.annotation.Nullable;
@@ -27,7 +29,8 @@ public class ItemWizardHandbook extends Item {
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, net.minecraft.client.util.ITooltipFlag flag) {
tooltip.add("\u00A77" + net.minecraft.client.resources.I18n.format("item." + Wizardry.MODID + ":wizard_handbook.author", AUTHOR));
tooltip.add(Wizardry.proxy.translate("item." + Wizardry.MODID + ":wizard_handbook.author",
new Style().setColor(TextFormatting.GRAY), AUTHOR));
}
@Override
@@ -42,12 +42,12 @@ public class Curse extends PotionMagicEffect {
super.renderInventoryEffect(x, y, effect, mc);
String name = net.minecraft.client.resources.I18n.format(this.getName());
String name = Wizardry.proxy.translate(this.getName());
// Amplifier 0 (which would be I) is not rendered and the tooltips only go up to X (amplifier 9)
// The vanilla implementation uses elseifs and only goes up to 4... how lazy.
if(effect.getAmplifier() > 0 && effect.getAmplifier() < 10){
name = name + " " + net.minecraft.client.resources.I18n.format("enchantment.level." + (effect.getAmplifier() + 1));
name = name + " " + Wizardry.proxy.translate("enchantment.level." + (effect.getAmplifier() + 1));
}
List<String> lines = mc.fontRenderer.listFormattedStringToWidth(name, 100);
@@ -34,8 +34,6 @@ import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
@@ -639,9 +637,8 @@ public abstract class Spell extends IForgeRegistryEntry.Impl<Spell> implements C
* Returns the translated display name of the spell, without formatting (i.e. not coloured). <b>Client-side
* only!</b> On the server side, use {@link TextComponentTranslation} (see {@link Spell#getNameForTranslation()}).
*/
@SideOnly(Side.CLIENT)
public String getDisplayName(){
return net.minecraft.client.resources.I18n.format(getTranslationKey());
return Wizardry.proxy.translate(getTranslationKey());
}
/**
@@ -656,9 +653,8 @@ public abstract class Spell extends IForgeRegistryEntry.Impl<Spell> implements C
* Returns the translated display name of the spell, with formatting (i.e. coloured). <b>Client-side only!</b> On
* the server side, use {@link TextComponentTranslation} (see {@link Spell#getNameForTranslationFormatted()}).
*/
@SideOnly(Side.CLIENT)
public String getDisplayNameWithFormatting(){
return this.getElement().getFormattingCode() + net.minecraft.client.resources.I18n.format(getTranslationKey());
return Wizardry.proxy.translate(getTranslationKey(), getElement().getColour());
}
/**
@@ -673,9 +669,8 @@ public abstract class Spell extends IForgeRegistryEntry.Impl<Spell> implements C
* Returns the translated description of the spell, without formatting. <b>Client-side only!</b> You should not need
* to use this on the server side.
*/
@SideOnly(Side.CLIENT)
public String getDescription(){
return net.minecraft.client.resources.I18n.format(getDescriptionTranslationKey());
return Wizardry.proxy.translate(getDescriptionTranslationKey());
}
/**
@@ -81,7 +81,7 @@ item.ebwizardry\:wizard_handbook.desc=by %1$s
item.ebwizardry\:wand.generic=wand
item.ebwizardry\:wand.buff=+%1$s %2$s potency
item.ebwizardry\:wand.buff=+%1$s%% %2$s potency
item.ebwizardry\:wand.spell=Current Spell\: %1$s
item.ebwizardry\:wand.mana=Mana\: %1$s/%2$s
item.ebwizardry\:wand.progression=Progression\: %1$s/%2$s
@@ -204,7 +204,7 @@ item.ebwizardry\:magic_silk.name=Magical Silk
item.ebwizardry\:spectral_dust.name=Spectral Dust
item.ebwizardry\:wizard_armour.legendary=Legendary
item.ebwizardry\:wizard_armour.buff=-%1$s %2$s cost
item.ebwizardry\:wizard_armour.buff=-%1$s%% %2$s cost
item.ebwizardry\:wizard_armour.mana=Mana\: %1$s/%2$s
item.ebwizardry\:wizard_hat.name=Wizard Hat
@@ -81,7 +81,7 @@ item.ebwizardry\:wizard_handbook.desc=Your not-so-pocket-sized guide to the arca
item.ebwizardry\:wand.generic=wand
item.ebwizardry\:wand.buff=+%1$s %2$s potency
item.ebwizardry\:wand.buff=+%1$s%% %2$s potency
item.ebwizardry\:wand.spell=Current Spell\: %1$s
item.ebwizardry\:wand.mana=Mana\: %1$s/%2$s
item.ebwizardry\:wand.progression=Progression\: %1$s/%2$s
@@ -204,7 +204,7 @@ item.ebwizardry\:magic_silk.name=Magical Silk
item.ebwizardry\:spectral_dust.name=Spectral Dust
item.ebwizardry\:wizard_armour.legendary=Legendary
item.ebwizardry\:wizard_armour.buff=-%1$s %2$s cost
item.ebwizardry\:wizard_armour.buff=-%1$s%% %2$s cost
item.ebwizardry\:wizard_armour.mana=Mana\: %1$s/%2$s
item.ebwizardry\:wizard_hat.name=Wizard Hat