Page 1 of 1

Problems getting the Localized Names of Items

Posted: Mon Sep 07, 2026 5:55 pm
by picklock
While working on one of my mods, I'm having trouble understanding something.

In the mod, I display a list of items in a GUI. The localized names of the items are shown as their names. I determine the localized names using the following code, based on the items’ internal names contained in a table generated by the mod:

Code: Select all

local myLocalName = prototypes.item[myTable[i].name].localised_name
I add the localized names of the items to the list in the GUI using the following code:

Code: Select all

my_gui_table.add{type = 'label', caption = myLocalName, style = 'bold_label'}
That works fine.

Now, as part of the updates for Factorio version 2.1, I want to add a sorting function to the list of items in the mod. So I took the variable described above, which contains the supposed localized names of the items, and wanted to add the localized names to the table so I could sort by them. However, the localized names aren’t being added to the table. When I try to print the contents of the variable to the console using the following code, it outputs “table.”

Code: Select all

myPlayer.print(tostring(myLocalName))
Now I’m a bit confused, because the localized name is displayed correctly in the GUI list, but I apparently can’t insert it into a table. What am I doing wrong? Or how can I use the internal name to transfer the localized name to a variable or add it to a table?

Re: Problems getting the Localized Names of Items

Posted: Mon Sep 07, 2026 6:14 pm
by Bilka
The localised_name in this case is a LocalisedString so something like {"item-name.iron-plate"}. If you try to sort by that, it will sort by exactly that, not the string that's displayed in the GUI (like Iron plate in English or Eisenplatte in German). If you want to sort by the translated result you need to use LuaPlayer::request_translations to get the translations and then use those for sorting.

Re: Problems getting the Localized Names of Items

Posted: Mon Sep 07, 2026 6:21 pm
by picklock
Hi Bilka,

Thank you for the quick response.