[REQUEST]Expose recipe.localised_name to LUA data stage
[REQUEST]Expose recipe.localised_name to LUA data stage
My Recycling Machines mod creates a recycling recipe for pretty much every recipe in game, including mods. Building the Recycling Recipe's localised name is a nightmare. Sometimes the original items name is in the locale file item-name section, sometimes it's in the entity-name. Mod authors aren't consistent about which section they use, in fact Vanilla isn't either. As a result, my mod has built up a lookup table to tell my code which section of the locale file to find the original item/entity name in. And in some cases I have to duplicate a mod's locale entry because it's in the 'wrong' section of the locale compared with other things in the same vanilla subgroup.
None of this would be necessary in my code if a recipe's localised_name property was exposed to LUA in the data stage.
Or alternatively, if the vanilla game forced mod authors to put names of things in the correct part of the locale file by erroring if they didn't. And if the devs were also consistent about where they put locale. (See 'Rail' for an example)
None of this would be necessary in my code if a recipe's localised_name property was exposed to LUA in the data stage.
Or alternatively, if the vanilla game forced mod authors to put names of things in the correct part of the locale file by erroring if they didn't. And if the devs were also consistent about where they put locale. (See 'Rail' for an example)
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Localized Name is not existing in data stage. It's only visible in player guis.
What do you think happens if an english and a german player join the same Server with different data tables?
What do you think happens if an english and a german player join the same Server with different data tables?
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Every items localised names should always be {"item-name.myitem"} unless specified differently in the prototype (which you can read at data stage) and unless the mod author forgot to put it into the locale.cfg in which case the game automatically tries to find it in __entity-name__ instead. So...what you really want would be i guess that the "automatic backup lookup" works for every localised string, because from what you say it sounds like it doesn't yet.
Care to quote the rail example btw?
Care to quote the rail example btw?
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
They have the mod on their client and it uses the localisation from the client. My mod runs on their client so would pick up their localised strings.steinio wrote:Localized Name is not existing in data stage. It's only visible in player guis.
What do you think happens if an english and a german player join the same Server with different data tables?
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Where can I find it in the prototype?eradicator wrote:Every items localised names should always be {"item-name.myitem"} unless specified differently in the prototype (which you can read at data stage)
I do have a backup which is "Cannot find localised name" kind of message.and unless the mod author forgot to put it into the locale.cfg in which case the game automatically tries to find it in __entity-name__ instead. So...what you really want would be i guess that the "automatic backup lookup" works for every localised string, because from what you say it sounds like it doesn't yet.
The type of things I've found are ( for example) the vanilla game might store the localised names of storage sub-grpup in the item-name section, but a mod author might create a storage chest in the same sub-group and put the localisation in the entity-name.
Rail is localised in entity-name, everything else rail related in item-name (or vice versa, I am not on computer)Care to quote the rail example btw?
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
And then there's equipment-name locale section as well.
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Thanks for that.steinio wrote:See viewtopic.php?f=28&t=32611&p=278509&hil ... ed#p207308
My specific requirements are quite simple. When players hover over one of my Recycling Recipes I want to set what the user sees to:
recyclingrecipe.localestring = {"recipe-name.recycledparts",{<the_locale_string_of what_I_am_recycling>}}
When the user hovers over the Recycling Recipe they should see (in English) "Recycled <original_item_name> parts"
It is not possible to know (reliably) where to find the <the_locale_string_of what_I_am_recycling> in the locale file. It can be any of item-name, entity-name, equipment-name and it is not predictable which one. The item's sub-group is a good pointer, but not 100% accurate. And mods do not follow the conventions either when adding to the locale files.
And then when Mods introduce new subgroups, I end up with giant lookup tables like this:
big lookup table
If my mod is doing this all wrong, and there is a way to reliably know where to find localestring, please somebody tell me.Although my request is for the actual string to be exposed in LUA data stage, just the locale section would be as good.
Last edited by DRY411S on Thu Feb 15, 2018 7:23 pm, edited 1 time in total.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
.localised_name but to avoid confusion: this is only available if the mod explicitly overrides default behavior (base game does this in some places such as barreling recipes) by specifiying that in the data stage.DRY411S wrote:Where can I find it in the prototype?eradicator wrote:Every items localised names should always be {"item-name.myitem"} unless specified differently in the prototype (which you can read at data stage)
How do you even detect if you could find a localised name or not? You're not supposed to be able to do that.DRY411S wrote:I do have a backup which is "Cannot find localised name" kind of message.and unless the mod author forgot to put it into the locale.cfg in which case the game automatically tries to find it in __entity-name__ instead. So...what you really want would be i guess that the "automatic backup lookup" works for every localised string, because from what you say it sounds like it doesn't yet.
Rail is kinda weird anyway with how it internally works \o/. And as i said before a mod author doesn't purposely store stuff in entity-name, they just forget to put an item-name. Basically from what i know the game does:DRY411S wrote:The type of things I've found are ( for example) the vanilla game might store the localised names of storage sub-grpup in the item-name section, but a mod author might create a storage chest in the same sub-group and put the localisation in the entity-name.Rail is localised in entity-name, everything else rail related in item-name (or vice versa, I am not on computer)Care to quote the rail example btw?
1) look if the prototype specified .localised_name. if not ->
2) look if there is a locale item-type.item-name. if not ->
3) look if there is a locale item-place-result-type.item-place-result-name (place result would be "entity" for lost of things, but could be equipment too, or nothing)
edit:
Testing around with cursor_stack.prototype.localised_name it might be that 2) and 3) are the other way around, so that it looks if there is a place result first. If that is the case you should be able to fix (almost?) all "irregulars" automatically. Also looking at your lookup table it looks like your going by item subgroup where you should be looking for item type imho. So try (pseudocode)
if item.placeable then placeable-result-name, else item-name.
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Not TL:DR, plenty to think about thank you, and too much to break out individually and comment.
However, item-type is never going to work in this scenario. There are so few compared with sub-groups, as I think my lookup table shows.
Type item is divided into groups then into sub-groups. But there are other types that are not 'item' that are also recyclable.
However, item-type is never going to work in this scenario. There are so few compared with sub-groups, as I think my lookup table shows.
Type item is divided into groups then into sub-groups. But there are other types that are not 'item' that are also recyclable.
Types hierachy
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Well but it is, or rather, you don't even need item-type. In fact i just wrote a function that correctly generates all locale names for vanilla + xanders (and a few small ones) mods items as far as i can tell. The only things that don't generate correctly in control stage are barrels and the blueprint, but i know that those have .localised_name specified in the prototype, so it's easy to read in data stage.DRY411S wrote: However, item-type is never going to work in this scenario. :) There are so few compared with sub-groups, as I think my lookup table shows.
Code: Select all
/c
print('\n\n\n\n\n')
for k,v in pairs(game.item_prototypes) do
local real = v.localised_name[1]
local derived
if v.place_result then
derived = 'entity-name.'..v.place_result.name
elseif v.place_as_equipment_result then
derived = 'equipment-name.'..v.place_as_equipment_result.name
-- elseif v.localised_name then --data stage only
-- derived = v.localised_name
else
derived = 'item-name.'..v.name
end
if real ~= derived then
print('Failed: ',k,real,derived)
end
end
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Thanks I'll study this more after a goods night sleep.
Is the game data structure available in the data stage of the ermmm... game?
Is the game data structure available in the data stage of the ermmm... game?
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Nope. That was just for demonstration. In data you have direct access to data.raw after all.DRY411S wrote: Is the game data structure available in the data stage of the ermmm... game?
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Your code works 100% in vanilla, and almost 100% with all the mods I've tried thank you.
Where it doesn't work with mods, should I be suggesting to the mod authors that they change their locale file?
Where it doesn't work with mods, should I be suggesting to the mod authors that they change their locale file?
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
I have no clue, that would depend highly on what kind of item/mod that is. I'd rather assume there's some erorr/edge case that my code is still missing. Care to post examples?DRY411S wrote:Your code works 100% in vanilla, and almost 100% with all the mods I've tried thank you.
Where it doesn't work with mods, should I be suggesting to the mod authors that they change their locale file?
Also i just noticed there's one major bug in my code in that it checks v.localised_name last when it should be checked first (i.e. before place_result), mostly because i tested in control stage :P.
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
It doesn't work with the valve in Bob's Logistics mod, or with either of the items in the Rail Loader Mod.
It's very irritating that there are occasional glitches in the odd Mod here and there.
It's very irritating that there are occasional glitches in the odd Mod here and there.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Can you dump the prototypes of those two (and the relevant config sections?) and post them here? (Also did you fix the bug i mentiond above?)
(Also unrelated...why does the total raw tooptip show player ports :P)
Edit:
Oh, and the code of the function you're actually using in data stage. I have a hunch about some problematic details that i'd like to check.
(Also unrelated...why does the total raw tooptip show player ports :P)
Edit:
Oh, and the code of the function you're actually using in data stage. I have a hunch about some problematic details that i'd like to check.
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
The code runs fine without any fix. If I'd tested for localised_name earlier in the logic, then Bob's Valve would not be an issue, I agree. I will change it as you suggest.eradicator wrote:Can you dump the prototypes of those two (and the relevant config sections?) and post them here? (Also did you fix the bug i mentiond above?)
There are very, very few prototypes with localised_name in vanilla, and most of them I don't recycle anyway (like barrels with fluids in for example, I recycle only empty barrels).
Here's a logfile dump of every data.raw.item (including those in mods I'm testing with). There are 38 items with localised_name set.
Don't understanderadicator wrote:(Also unrelated...why does the total raw tooptip show player ports )
eradicator wrote:Edit:
Oh, and the code of the function you're actually using in data stage. I have a hunch about some problematic details that i'd like to check.
The code with old lookup code commented out to preserve it just in case
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Well, no. It doesn't run fine, it has a bug :P. And there's no reason to not fix the bug. Also just because vanilla doesn't use localised_name that often doesn't mean you can just ignore it. I use it in some places for example to generate names because static names don't work in some cases. Other mods do this too.DRY411S wrote:The code runs fine without any fix. If I'd tested for localised_name earlier in the logic, then Bob's Valve would not be an issue, I agree. I will change it as you suggest.
There are very, very few prototypes with localised_name in vanilla, and most of them I don't recycle anyway (like barrels with fluids in for example, I recycle only empty barrels).
Here's the hopefully 100% correct version:
Code: Select all
local derived --courtesy of eradicator
if item.localised_name then
derived = item.localised_name
elseif item.place_result then
derived = 'entity-name.'..item.place_result
elseif item.placed_as_equipment_result then
derived = 'equipment-name.'..item.placed_as_equipment_result
else
derived = 'item-name.'..item.name
end
Re: [REQUEST]Expose recipe.localised_name to LUA data stage
Yes it doesn't run fine, it does have a bug. This is what happens when I try to compose a post in between testing, work and 10 family members arriving for the weekend at various intervals.
Thanks for the new code including the cheeky acknowledgement comment. Rest assured the released version will fully recognise your help in fixing this, and in the changelog, not just buried in code.
Mods can close this request. Eradicator has shown how this requested feature is not necessary.
Thanks for the new code including the cheeky acknowledgement comment. Rest assured the released version will fully recognise your help in fixing this, and in the changelog, not just buried in code.
Mods can close this request. Eradicator has shown how this requested feature is not necessary.
Last edited by DRY411S on Fri Feb 16, 2018 11:00 pm, edited 1 time in total.