[REQUEST]Expose recipe.localised_name to LUA data stage

Things that we aren't going to implement
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

[REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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)

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2638
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by steinio »

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?
Image

Transport Belt Repair Man

View unread Posts

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by eradicator »

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?

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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?
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.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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)
Where can I find it in the prototype?
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.
I do have a backup which is "Cannot find localised name" kind of message.

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.
Care to quote the rail example btw?
Rail is localised in entity-name, everything else rail related in item-name (or vice versa, I am not on computer)

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

And then there's equipment-name locale section as well.


User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

Thanks for that. :)

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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by eradicator »

DRY411S wrote:
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)
Where can I find it in the prototype?
.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:
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.
I do have a backup which is "Cannot find localised name" kind of message.
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: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.
Care to quote the rail example btw?
Rail is localised in entity-name, everything else rail related in item-name (or vice versa, I am not on computer)
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:

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.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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.
Types hierachy

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by eradicator »

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.
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.

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

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by eradicator »

DRY411S wrote: Is the game data structure available in the data stage of the ermmm... game?
Nope. That was just for demonstration. In data you have direct access to data.raw after all.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by eradicator »

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?
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?

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.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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.
bob-valve.png
bob-valve.png (219.45 KiB) Viewed 5750 times
railloader.png
railloader.png (225.09 KiB) Viewed 5750 times

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by eradicator »

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.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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?)
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 a logfile dump of every data.raw.item (including those in mods I'm testing with). There are 38 items with localised_name set.
factorio-current.log
(326.1 KiB) Downloaded 80 times
eradicator wrote:(Also unrelated...why does the total raw tooptip show player ports :P)
Don't understand
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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by eradicator »

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).
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.

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
As i expected there was another issue. You were still using item-name when you really need to use the place-result name. This only seems to work because in vanilla and most mods they happen to be the same. Also i tested for the very rare case in which an equipment is also placeable as entity, in that case it uses the entity name, so no changes are needed for that.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [REQUEST]Expose recipe.localised_name to LUA data stage

Post by DRY411S »

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.
Last edited by DRY411S on Fri Feb 16, 2018 11:00 pm, edited 1 time in total.

Post Reply

Return to “Won't implement”