Page 1 of 1
Reusing previously localized strings in localization file
Posted: Fri Sep 16, 2016 12:06 pm
by canidae
I noticed that it's possible to reference certain localized strings in your mod's localization. For example, you can add a localization like: "test_msg = Test: __ENTITY__coal__" and it'll show up as "Test: Coal" for English localization in the game (and I'm guessing as "Test: Kull" for Norwegian localization).
(Note: I'm currently at work and I might not remember the "__ENTITY__coal__" syntax entirely correct)
In a mod I wish to reuse localization of technology names, but I was unable to find any examples of this. This is what I'm trying:
Code: Select all
[virtual-signal-name]
grenade-damage = [Auto Research] __TECHNOLOGY__grenade-damage__ (signal value sets tech level)
research-speed = [Auto Research] __TECHNOLOGY__research-speed__ (signal value sets tech level)
toolbelt = [Auto Research] __TECHNOLOGY__toolbelt__ (signal value sets tech level)
This also leads me to a 2nd question:
Neither could I find a way to reference earlier localization in the same file, i.e:
Code: Select all
[auto-research]
signal_text_append = (signal value sets tech level)
[virtual-signal-name]
grenade-damage = [Auto Research] __TECHNOLOGY__grenade-damage__ __auto-reseach.signal_text_append__
research-speed = [Auto Research] __TECHNOLOGY__research-speed__ __auto-reseach.signal_text_append__
toolbelt = [Auto Research] __TECHNOLOGY__toolbelt__ __auto-reseach.signal_text_append__
Is this possible, or is it necessary to duplicate the localization from the base game?
Re: Reusing previously localized strings in localization file
Posted: Fri Sep 16, 2016 12:13 pm
by LuziferSenpai
canidae wrote:I noticed that it's possible to reference certain localized strings in your mod's localization. For example, you can add a localization like: "test_msg = Test: __ENTITY__coal__" and it'll show up as "Test: Coal" for English localization in the game (and I'm guessing as "Test: Kull" for Norwegian localization).
(Note: I'm currently at work and I might not remember the "__ENTITY__coal__" syntax entirely correct)
In a mod I wish to reuse localization of technology names, but I was unable to find any examples of this. This is what I'm trying:
Code: Select all
[virtual-signal-name]
grenade-damage = [Auto Research] __TECHNOLOGY__grenade-damage__ (signal value sets tech level)
research-speed = [Auto Research] __TECHNOLOGY__research-speed__ (signal value sets tech level)
toolbelt = [Auto Research] __TECHNOLOGY__toolbelt__ (signal value sets tech level)
This also leads me to a 2nd question:
Neither could I find a way to reference earlier localization in the same file, i.e:
Code: Select all
[auto-research]
signal_text_append = (signal value sets tech level)
[virtual-signal-name]
grenade-damage = [Auto Research] __TECHNOLOGY__grenade-damage__ __auto-reseach.signal_text_append__
research-speed = [Auto Research] __TECHNOLOGY__research-speed__ __auto-reseach.signal_text_append__
toolbelt = [Auto Research] __TECHNOLOGY__toolbelt__ __auto-reseach.signal_text_append__
Is this possible, or is it necessary to duplicate the localization from the base game?
You need to write:
Code: Select all
[virtual-signal-name]
grenade-damage = [Auto Research] __1__ __2__
research-speed = [Auto Research] __1__ __2__
toolbelt = [Auto Research] __1__2__ __3__
Not more!!
Re: Reusing previously localized strings in localization file
Posted: Fri Sep 16, 2016 12:22 pm
by canidae
Thanks for your reply, but I don't think that'll help me. I'm not printing it out to the console and don't supply the localization strings with parameters (i.e. the __1__, __2__, etc).
The localization is used by extended data:
Code: Select all
data:extend({
{
type = "virtual-signal",
name = "grenade-damage",
icon = "__auto-research__/graphics/icons/signal/grenade-damage.png",
subgroup = "virtual-signal-number",
order = "r[auto-research]-[01]"
}
}
Re: Reusing previously localized strings in localization file
Posted: Fri Sep 16, 2016 1:15 pm
by LuziferSenpai
canidae wrote:Thanks for your reply, but I don't think that'll help me. I'm not printing it out to the console and don't supply the localization strings with parameters (i.e. the __1__, __2__, etc).
The localization is used by extended data:
Code: Select all
data:extend({
{
type = "virtual-signal",
name = "grenade-damage",
icon = "__auto-research__/graphics/icons/signal/grenade-damage.png",
subgroup = "virtual-signal-number",
order = "r[auto-research]-[01]"
}
}
I was thinking you using a script ...
Than you need to do this:
Code: Select all
[virtual-signal-name]
grenade-damage = [Auto Research] Grenade damage (signal value sets tech level)
research-speed = [Auto Research] Research speed (signal value sets tech level)
toolbelt = [Auto Research] Toolbelt (signal value sets tech level)
The __1__ is only for guys that using scripts for making entitys, items, recipes etc. . Like my Straight Pipes or Rail Tanker

Re: Reusing previously localized strings in localization file
Posted: Fri Sep 16, 2016 1:31 pm
by aubergine18
I'm pretty sure there's a way to do it, but I can't remember the mod where I saw it done.
Localisation strings are nestable, both in suff from control.lua and, to a lesser extent, from prototype definitions and even .cfg files. A good example in .cfg files is the __CONTROL__ keyword.
It looks like the main issue canidae is having is determining which keyword to use. I'll have hunt through my mods folder (it's got over 200 mods in it, so I may be some time)...
Re: Reusing previously localized strings in localization file
Posted: Fri Sep 16, 2016 1:48 pm
by canidae
aubergine18 wrote:I'm pretty sure there's a way to do it, but I can't remember the mod where I saw it done.
Localisation strings are nestable, both in suff from control.lua and, to a lesser extent, from prototype definitions and even .cfg files. A good example in .cfg files is the __CONTROL__ keyword.
It looks like the main issue canidae is having is determining which keyword to use. I'll have hunt through my mods folder (it's got over 200 mods in it, so I may be some time)...
Spot on.
I'm already using "__CONTROL__" and I found "__ENTITY__" and "__ITEM__" in the base game files, but nothing for technologies.
Re: Reusing previously localized strings in localization file
Posted: Fri Sep 16, 2016 1:59 pm
by aubergine18
I'll just dump search results, including mod name for reference, as I find them...
__ENTITY__ followed by entity prototype name:
Engineersvsenvironmentalist_0.1.3/locale/en/ores.cfg:
25 [item-name]
26: gold-ore=__ENTITY__gold-ore__
This shows, in .cfg file, the locale key for an item name simply referring to the locale key for its corresponding entity name.
__CONTROL__ followed by custom-input prototype event name:
base/campaigns/beta/level-01/locale/bg/beta_level-01.cfg:
3: goal-enter-car-insert-fuel=Постройте колата, вкарайте гориво (въглища) в нея и влезте с __CONTROL__toggle-driving__.
__ITEM__ followed by item prototype name:
base/campaigns/beta/level-03/locale/ja/beta_level-03.cfg:
4: msg-could-make-more-2=__ITEM__defender-capsule__
I imagine there's also a __FLUID__ one.
__hold__ and __press__ - looks like these are direct references to existing locale keys:
base/campaigns/demo/level-01/locale/ar/demo_level-01.cfg:
2: goal-close-character-screen=.(__press __CONTROL__close-gui) ةيصخشلا ةهجاو قلغا
17: goal-mine-iron-ore-precise=__hold __CONTROL__mine__): __1__/__2) ديدحلا ماخ نع بقن
Looking at the above, it seems that __ in front of something denotes a reference, and __ after something is a delimiter at the end of the reference. So, if the something after a reference is not an alphanumeric character, it's treated as a delimiter automatically - like the __2 above is delimited by )
Re: Reusing previously localized strings in localization file
Posted: Fri Sep 16, 2016 2:03 pm
by aubergine18
That's all I could find so far. Didn't see any ref to __TECHNOLOGY__ or anything like that. It might be worth scouring any mods made by Konan, Rseding91 or any of the other devs from Wube, as they are likely to use little-known tricks in their mods.
If all else fails, ask for a __TECHNOLOGY__ marker in the Modding Interface Requests forum.
Re: Reusing previously localized strings in localization file
Posted: Mon Sep 19, 2016 3:43 pm
by aubergine18
@canidae did you ever find a solution for this?
I've realised that the groups in locale files are actually just part of the locale key names that appear within them, for example:
Code: Select all
[some-group]
some-thing = some text
Is equivalent to:
So you might be able to do something like this:
Code: Select all
my-thing = __some-group.some-name__
It's possible that a mod name is needed, for example:
Code: Select all
my-thing = __ModName__some-group.some.name__
I've not had chance to test any of this yet, but might be worth a try if you have time.
Re: Reusing previously localized strings in localization file
Posted: Mon Sep 19, 2016 3:58 pm
by canidae
aubergine18 wrote:@canidae did you ever find a solution for this?
Code: Select all
my-thing = __some-group.some-name__
It's possible that a mod name is needed, for example:
Code: Select all
my-thing = __ModName__some-group.some.name__
I've not had chance to test any of this yet, but might be worth a try if you have time.
No, I haven't found a solution for either problem.
I've tested out the examples you gave above and some more, neither of these work:
Code: Select all
grenade-damage = [Auto Research] Grenade damage __auto-research.signal_append__
grenade-damage = [Auto Research] Grenade damage __auto-research__auto-research.signal_append__
grenade-damage = [Auto Research] Grenade damage __auto-research.auto-research.signal_append__
grenade-damage = [Auto Research] Grenade damage __auto-research__.auto-research.signal_append__
Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 1:51 am
by Mooncat
Hi all,
How about the "localised_name" property? I know it is in entity prototype, item prototype and recipe prototype, but haven't tried it on virtual signal prototype myself.
Try to add this when defining the prototype:
Code: Select all
localised_name = {"virtual-signal-name.grenade-damage", {"(The technology locale key)"}, {"auto-research.signal_text_append"}}
While keep the locale to be
Code: Select all
[auto-research]
signal_text_append = (signal value sets tech level)
[virtual-signal-name]
grenade-damage = [Auto Research] __1__ __2__
Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 1:53 am
by aubergine18
EDIT: I completely misread the comment above, thinking it was for GUI elements, not prototypes.
But what if you want to use existing locale keys from, say, an entity description (rather than a GUI caption)?
Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 2:03 am
by Mooncat
aubergine18 wrote:But what if you want to use existing locale keys from, say, an entity description (rather than a GUI caption)?
Entity descriptions are under [entity-description], so...
Code: Select all
{"entity-description.(entity name)"}
would do the trick.
Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 2:37 am
by aubergine18
If setting the caption of a GUI element, yes. But what about setting the description of the entity itself, or item, etc. Those are defined in data.lua, not control.lua.
Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 3:04 am
by Mooncat
aubergine18 wrote:If setting the caption of a GUI element, yes. But what about setting the description of the entity itself, or item, etc. Those are defined in data.lua, not control.lua.
Oh! I have no idea then. Maybe we need localised_description or something more powerful like your request.
Though I don't think this topic is really related to whether it is in data.lua or control.lua.

Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 3:24 pm
by canidae
Mooncat wrote:Hi all,
How about the "localised_name" property? I know it is in entity prototype, item prototype and recipe prototype, but haven't tried it on virtual signal prototype myself.
Hi there Mooncat. Thanks for Creative Mod[e], and for the tip on the localized_name property. Your suggestion helped me solve my problem. Since I already had a "[Auto Research] __1__" string I wanted to reuse, I ended up with some nested strings instead. This is how it turned out in the end:
Code: Select all
prefix = [Auto Research] __1__
...
signal_text = __1__ (signal value sets tech level, tech will be deprioritized if value is set to 0)
Code: Select all
{
type = "virtual-signal",
name = "grenade-damage",
localised_name = {"auto-research.prefix", {"auto-research.signal_text", {"technology-name.grenade-damage"}}},
icon = "__auto-research__/graphics/icons/signal/grenade-damage.png",
subgroup = "virtual-signal-auto-research",
order = "g[auto-research]"
},
Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 3:59 pm
by Mooncat
My pleasure!

Happy modding!
Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 4:45 pm
by aubergine18
Oh wow I didn't realise localised_name could be used in prototype definitions like that. Completely misread Mooncat's earlier comment.
Looking at
data.raw it's only used one single time for "dummy-selection-tool" prototype. Great find!
@canidae: Does it change the name or description of the signal? Or something else? (I assume description)
Re: Reusing previously localized strings in localization file
Posted: Tue Sep 20, 2016 5:35 pm
by Mooncat
aubergine18 wrote:Oh wow I didn't realise localised_name could be used in prototype definitions like that. Completely misread Mooncat's earlier comment.
Looking at
data.raw it's only used one single time for "dummy-selection-tool" prototype. Great find!
@canidae: Does it change the name or description of the signal? Or something else? (I assume description)
It only changes the name. So I'm afraid it is not what you are looking for.
(I got this property by luck. When I checked the API doc of LuaEntityPrototype, I found the localised_name property and assumed it should also be available in data.lua. lol)