Page 1 of 1

How to localize arbitrary item name?

Posted: Wed Sep 28, 2016 11:17 pm
by akastalker
Hi,

How can I localize item name when I don't know the type of an item? Like, is it entity, equipment or simple item?

Say, there is ghost entity that is blocked by laying around items. When my script revives ghost entity, I want to put these items into player's inventory and to show flying text "+10 Iron plate (50)" like in vanilla game when you build entity over items on the ground.
Problem is, I have item names only and don't know how to convert them into localised strings, because their names are grouped by types for some reason, like: 'item-name.pistol', 'entity-name.splitter' or 'equipment-name.battery-equipment'.
Its strange how entities and equipment have respective item prototypes but don't have 'item-name.###' localisation strings.

PS. Also, revive() function does a good job returning list of removed items from ground with their respective count, however all item specific information (health, clip rounds, armour equipment, etc.) is lost. But that's something I'm trying not to think about right now.

Re: How to localize arbitrary item name?

Posted: Thu Sep 29, 2016 12:20 am
by aubergine18
Here's everything I know about localisation: https://github.com/aubergine10/Style/wiki/Localisation

In particular, look under the 'Parameters', 'Special Parameters' and 'Nested locale objects' headings.

Re: How to localize arbitrary item name?

Posted: Thu Sep 29, 2016 9:33 am
by akastalker
This is a wonderful tutorial, but it didn't help me.

In my script I have name of an object that I just picked up from the floor, and I don't know what that object is: item, entity or equipment.
I know, everything that can go into player's inventory is an item, or at least has an item counterpart,
but base mod localisation file contains only one 'stone-furnace' that is in section [entity-name] and don't have 'item-name.stone-furnace'.
I tried that __ITEM__stone-furnace__ thing and still getting "Unknown key: "item-name.stone-furnace"".
I wonder, how game engine handles localisation of items in inventory GUI...

So, still looking for solution.

Re: How to localize arbitrary item name?

Posted: Thu Sep 29, 2016 9:51 am
by Klonan
akastalker wrote: So, still looking for solution.

http://lua-api.factorio.com/latest/LuaI ... lised_name

Example:

Code: Select all

/c game.player.print(game.item_prototypes["iron-plate"].localised_name

Re: How to localize arbitrary item name?

Posted: Thu Sep 29, 2016 10:14 am
by akastalker
Wow, wasn't aware I had access to prototypes in runtime. It's an eye opener, thank you.
@aubergine18, can you update your tutorial to include this approach?
Consider case closed.

Re: How to localize arbitrary item name?

Posted: Thu Sep 29, 2016 11:17 am
by Ranakastrasz
akastalker wrote:Wow, wasn't aware I had access to prototypes in runtime.
You don't. Just a subset of the prototype.

Re: How to localize arbitrary item name?

Posted: Thu Sep 29, 2016 6:20 pm
by Rseding91
Ranakastrasz wrote:
akastalker wrote:Wow, wasn't aware I had access to prototypes in runtime.
You don't. Just a subset of the prototype.
Not for items. For items it's all of the properties every item prototype has.