Page 1 of 1

Is it possible to do localisation dynamical?

Posted: Tue Feb 06, 2018 5:17 am
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?

Re: Is it possible to do localisation dynamical?

Posted: Tue Feb 06, 2018 8:32 am
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__

Re: Is it possible to do localisation dynamical?

Posted: Tue Feb 06, 2018 11:15 am
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.