TheDoctorSoda Posted January 22, 2016 Share Posted January 22, 2016 So how would I localise an item's name in code, as opposed to a language file? Quote Link to comment Share on other sites More sharing options...
RANKSHANK Posted January 22, 2016 Share Posted January 22, 2016 Don't know why you'd want that but override Item.getItemStackDisplayName Quote I think its my java of the variables. Link to comment Share on other sites More sharing options...
TheDoctorSoda Posted January 22, 2016 Author Share Posted January 22, 2016 Thanks! What I want to do is have a few localisations such as metal.tin and metal.copper, and match them with component.plate and component.powder, so I can combine them to make Tin Plate, Tin Powder, Copper Plate, Copper Powder, etc. Quote Link to comment Share on other sites More sharing options...
LexManos Posted January 22, 2016 Share Posted January 22, 2016 Mixing and matching like that isnt advised because other languages have different syntaxes so its not always {Material} {Form} Quote I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon Link to comment Share on other sites More sharing options...
coolAlias Posted January 22, 2016 Share Posted January 22, 2016 What Lex says is very true, but don't let that discourage you - translations can be very flexible with just a little bit of formatting, as they ultimately use the Java Formatter class: // Lang file: yourmod.item.name=%s %s // results in "Tin Plate" yourmod.metal.tin.name=Tin yourmod.component.plate.name=Plate // Item code: @Override public String getItemStackDisplayName(ItemStack stack) { // Make sure to use #translateToLocalFormatted and pass the translations for each component as an argument return StatCollector.translateToLocalFormatted(getUnlocalizedName() + ".name", StatCollector.translateToLocal("yourmod.metal.tin.name"), StatCollector.translateToLocal("yourmod.component.plate.name")); Of course, it's up to you to determine which metal and component to use in the translation, probably using some kind of Object retrieved from NBT. But anyway, then languages with different ordering rules can translate it like so: // taking advantage of Formatter syntax to re-order the arguments: yourmod.item.name=%2$s %1$s // results in "Plate Tin" Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.