dynamic localized names

Place to get help with not working mods / modding interface.
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 401
Joined: Thu Dec 21, 2017 8:02 am
Contact:

dynamic localized names

Post by ownlyme »

when i enter something like
data.localised_name = { "__1__ ["..data.name.."]", {'item-name.' .. data.name}}
it results in Unknown key: "Copper plate [copper-plate]"
how do i get rid of this unknown key thing?

i wanted to make a mod where modders can see the internal names of everything
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

robot256
Filter Inserter
Filter Inserter
Posts: 793
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: dynamic localized names

Post by robot256 »

I was searching for info on manipulating other mods locale strings myself, and came across this gem of a thread. Apparently, there are many places the game can get the localised name of an item, and item-name.blah is not guaranteed to exist.

viewtopic.php?f=28&t=62107

In my case, I get what I need by reading the localised_string property of the source object prototype in data.raw, and using that as a variable in my own locale strings. I just remembered that this actually doesn't work. You can assign entity.localised_string, but it always reads as empty even if the mod you are referencing was loaded before. At this point I'm falling back on hard-coding whether to expect the mod's entity-description to be set or not.

Hiladdar
Fast Inserter
Fast Inserter
Posts: 214
Joined: Mon May 14, 2018 6:47 pm
Contact:

Re: dynamic localized names

Post by Hiladdar »

As I understand it, temporarily move the locale folder outside the mod and restart the game. At that point all in lieu of readable item name and description, the internal name will be displayed.

Hiladdar

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2805
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: dynamic localized names

Post by BlueTemplar »

ownlyme wrote:
Fri Mar 29, 2019 8:47 pm
i wanted to make a mod where modders can see the internal names of everything
What do you mean by "see" ?
Maybe, I'm misunderstanding, but :
For 0.16 we have Mod Developer Tools :
https://mods.factorio.com/mod/ModDeveloperTools
Image

And in 0.17 there's the show-debug-info-in-tooltips debug option, that looks to be largely inspired by this mod...
BobDiggity (mod-scenario-pack)

User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 471
Joined: Sun May 21, 2017 6:28 pm
Contact:

Re: dynamic localized names

Post by Therax »

ownlyme wrote:
Fri Mar 29, 2019 8:47 pm
when i enter something like
data.localised_name = { "__1__ ["..data.name.."]", {'item-name.' .. data.name}}
it results in Unknown key: "Copper plate [copper-plate]"
how do i get rid of this unknown key thing?

i wanted to make a mod where modders can see the internal names of everything
Placeholders like __1__ go into string templates, which are in locale files e.g. locale/en/mod-name.cfg.
The first entry in the table of a LocalisedString is the key for the template in the locale file.
So you need something like this in a .cfg file in locale/en/:

Code: Select all

[my-mod]
name-with-internal-name=__1__ [__2__]
And then set up the prototype during the data stage with something like the following:

Code: Select all

data.localised_name = { "my-mod.name-with-internal-name", {"item-name." .. data.name}, data.name }
Note that figuring out the correct entry for __1__ is more complex for things like recipes, which usually infer their name from their products.
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Post Reply

Return to “Modding help”