How to localize arbitrary item name?

Place to get help with not working mods / modding interface.
User avatar
akastalker
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Jun 27, 2016 10:52 pm
Contact:

How to localize arbitrary item name?

Post 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.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: How to localize arbitrary item name?

Post 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.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
akastalker
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Jun 27, 2016 10:52 pm
Contact:

Re: How to localize arbitrary item name?

Post 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.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5290
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to localize arbitrary item name?

Post 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
User avatar
akastalker
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon Jun 27, 2016 10:52 pm
Contact:

Re: How to localize arbitrary item name?

Post 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.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2173
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: How to localize arbitrary item name?

Post by Ranakastrasz »

akastalker wrote:Wow, wasn't aware I had access to prototypes in runtime.
You don't. Just a subset of the prototype.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Rseding91
Factorio Staff
Factorio Staff
Posts: 14363
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: How to localize arbitrary item name?

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding help”