Page 1 of 1

dynamic localized names

Posted: Fri Mar 29, 2019 8:47 pm
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

Re: dynamic localized names

Posted: Sat Mar 30, 2019 3:22 am
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.

Re: dynamic localized names

Posted: Sat Mar 30, 2019 3:32 pm
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

Re: dynamic localized names

Posted: Sat Mar 30, 2019 3:46 pm
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...

Re: dynamic localized names

Posted: Fri Apr 05, 2019 3:05 am
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.