Posted January 22, 20169 yr So how would I localise an item's name in code, as opposed to a language file?
January 22, 20169 yr Don't know why you'd want that but override Item.getItemStackDisplayName I think its my java of the variables.
January 22, 20169 yr Author 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.
January 22, 20169 yr Mixing and matching like that isnt advised because other languages have different syntaxes so its not always {Material} {Form} I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
January 22, 20169 yr 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" http://i.imgur.com/NdrFdld.png[/img]
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.