Is it possible to do localisation dynamical?

Place to get help with not working mods / modding interface.
ukezi
Filter Inserter
Filter Inserter
Posts: 392
Joined: Sat Jul 02, 2016 11:02 pm
Contact:

Is it possible to do localisation dynamical?

Post by ukezi »

I am working on a mod that has a few Items with a configurable number of tiers. Is it possible to do the localisation dynamical or set the screen name is Code?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Is it possible to do localisation dynamical?

Post by eradicator »

You can specify the localised name for each prototype in the prototype definition.

Code: Select all

localised_name = {"some_group.some_localisation_identifier", some_variable}
The base game does this for example for barreling:

Code: Select all

-- Generates a barrel item with the provided name and fluid definition using the provided empty barrel stack size
local function create_barrel_item(name, fluid, empty_barrel_item)
  local result =
  {
    type = "item",
    name = name,
    localised_name = {"item-name.filled-barrel", {"fluid-name." .. fluid.name}},
    icons = generate_barrel_item_icons(fluid, empty_barrel_item),
    icon_size = 32,
    flags = {"goes-to-main-inventory"},
    subgroup = "fill-barrel",
    order = "b[" .. name .. "]",
    stack_size = empty_barrel_item.stack_size
  }

  data:extend({result})
  return result
end
The localization file would then look something like this (from memory):

Code: Select all

[some_group]
some_localisation_identifier=SomeItemName Tier __1__
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Is it possible to do localisation dynamical?

Post by bobingabout »

Alternatively, this works too

Say your items are named... thing-1, thing-2 etc.

Code: Select all

[item-name]
thing=Thing
thing-1=__ITEM__thing__ 1
thing-2=__ITEM__thing__ 2
the __ITEM__thing__ part will assign the locale entry from "thing". then add the " 1" to the end of it. etc.

I use that in my mod, for example, on the artillery wagon to add MK2 and MK3 to the end of it, the name then reads as "Artillery wagon MK2", and the best part is that if you switch to another language, it automatically works with the other languages Artillery wagon entry.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Post Reply

Return to “Modding help”