Page 1 of 1
localised name as string
Posted: Tue Aug 16, 2016 3:37 pm
by steinio
Hello,
this bothers me for a long time and i need some help here please - i don't understand the localised string function.
I have following code:
Code: Select all
local force = game.forces.player
local current_research = force.current_research
text = "Current research: " .. tostring(current_research.localised_name)
but it only returns a table.
How can i get the localised name as a string?
Greetings steinio
Re: localised name as string
Posted: Tue Aug 16, 2016 3:57 pm
by prg
You can't get at the actual localised string from within Lua. It could differ for people in a multiplayer game using different locales, potentially leading to desyncs. You can only pass this table to LuaPlayer::print or set it as the caption for a GUI element or things like that so the game translates the text for you.
Re: localised name as string
Posted: Tue Aug 16, 2016 4:04 pm
by steinio
Ok thank you.
Can i pass it as a construct?
Saw this in some mods:
It get transfered to a gui flow text.
If i play with this i get only a "can't concat table" error.
Greetings steinio
Re: localised name as string
Posted: Tue Aug 16, 2016 4:25 pm
by prg
You can create a localization table yourself:
Code: Select all
game.player.print({"entity-name.fast-inserter"})
and pass parameters to fill in placeholders:
Code: Select all
game.player.print({"description.durability", 10, 20})
which can themselves be localization tables:
Code: Select all
game.player.print({"inventory-restriction.cant-be-burned", {"item-name.steel-plate"}})
so you could create a locale entry for your mod containing something like "current-research=Current research: __1__" to achieve what you want.
Re: localised name as string
Posted: Tue Aug 16, 2016 4:28 pm
by aubergine18
In short, anywhere you can specify some text to that will go on screen, you can either pass in static text (a string literal) --* or *-- a table defining a locale key and (optionally) parameters.
The first value of the table is the locale key, which Factorio will go find in the locale files in your mod, then any additional values in the table are parameters that can appear in the locale string as shown in prg's examples above.
Re: localised name as string
Posted: Tue Aug 16, 2016 4:31 pm
by steinio
Well sadly this all works only with .print() function.
Thank you for your help,
So i stay with current.research.name, this works but it's only the string left of the = in the locale.cfg.
Greetings steinio
Re: localised name as string
Posted: Tue Aug 16, 2016 4:34 pm
by prg
Setting the caption of a GUI element this way should work, too. If it doesn't, show the code.
Re: localised name as string
Posted: Sun Aug 21, 2016 8:59 am
by steinio
Had a look on other mods how they managed it.
Keywords are #locale #en #en.cfg
No modding tutorial covers this.
All localisation tutorials only mention game.print() what is not practically relevant.
SO i made a localisation file - important is the UTF8 without BOM encoding - now it works.
Greetings steinio