Custom item/entity translations

Things that already exist in the current mod API
Post Reply
bNarFProfCrazy
Fast Inserter
Fast Inserter
Posts: 194
Joined: Sat Apr 23, 2016 7:11 am
Contact:

Custom item/entity translations

Post by bNarFProfCrazy »

It would be nice if I could define in the prototype how an Entity/Item should be called in game without specifying a translation for the data.name key.

Example:

Code: Select all

tree_type = data.raw["tree"]["tree-02"]
tree_item = {
		type = "item",
		name = tree_type.name .. "-sapling",
		icon = tree_type.icon,
...
It would be nice if I could configure a function that resolves the name.

Code: Select all

localized_string("mytree.naming-template", localized_string("mytree.sapling"), localized_string("tree-02"))
So I only have to provide two translations "mytree.naming-template" (__2__ __1__) and "mytree.sapling" (Sapling) for the result "Tree 2 Sapling").
(This is also intended as a help for MK2-MK100 translations that only differ in the number and are a pain to maintain for different languages.)

Why I want this?
Well because I don't want to maintain translations for other (mod added) trees as well that would be all build in the same way. "Tree 9 Sapling", "Rubber Tree Sapling", "Dessert tree Sapling"....

------------------------------------------------

Or that I can provide a reference to a translation to be used.

Code: Select all

		type = "entity",
		name = tree_type.name .. "-small",
		localiced_name = tree_type.name,
		icon = tree_type.icon,
...
Maing "tree-02-small" using the same translations as "tree-02".

Why I want this:
Because in some cases, I have quite a lot different versions of the same thing and I don't want to maintain a translation for each of them.
(It does not matter if the tree is small or big, the only important thing is the name and maybe that the tree is not mature yet/is still growing)

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Custom item/entity translations

Post by DaveMcW »

naming-template=Tree __1__ __2__
sapling=Sapling
tree-02=2

Code: Select all

function localized_string(template, size, number)
  return {template, number, size}
end

game.player.print(localized_string("naming-template", "sapling", "tree-02"))

Rseding91
Factorio Staff
Factorio Staff
Posts: 13235
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Custom item/entity translations

Post by Rseding91 »

You can already do this. You just define the "localised_name" key for a prototype and it uses that.
If you want to get ahold of me I'm almost always on Discord.

bNarFProfCrazy
Fast Inserter
Fast Inserter
Posts: 194
Joined: Sat Apr 23, 2016 7:11 am
Contact:

Re: Custom item/entity translations

Post by bNarFProfCrazy »

Well that question is almost a year old and IIRC at that time that feature was not present.
I already found it in the mean time. Thanks for the answer anyway.

For everybody that might stumble about this thread in the future.
Here is the link to the docs: http://lua-api.factorio.com/latest/Conc ... isedString

Post Reply

Return to “Already exists”