locale string access from lua

Place to get help with not working mods / modding interface.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

locale string access from lua

Post by binbinhfr »

Hi,

I'd like to access some kind of locale from the lua code (for example, to display messages in the locale langage).
So is there a function like GetStringLocale( "error-message" )

and in the locales there would be :
error-message = This is an error message
or
error-message = Ceci est un message d'erreur
My mods on the Factorio Mod Portal :geek:
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: locale string access from lua

Post by binbinhfr »

no idea ?

I really wonder how to generate locale translated message errors (or any kind of messages)...
My mods on the Factorio Mod Portal :geek:
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: locale string access from lua

Post by DaveMcW »

Code: Select all

player.print({"error-message"})
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: locale string access from lua

Post by binbinhfr »

DaveMcW wrote:

Code: Select all

player.print({"error-message"})
Thanks for your answer, but could you be more precise, concerning what I should write into en.cfg in the locale dir ?
At the beginning of en.cfg, I simply put :

Code: Select all

error-message = Test error message
But it does not work. It gives me an

Code: Select all

unknown key : "error-message"
My mods on the Factorio Mod Portal :geek:
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: locale string access from lua

Post by prg »

Where exactly did you put that file?
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: locale string access from lua

Post by binbinhfr »

prg wrote:Where exactly did you put that file?
My fault : I forgot to relaunch completely factorio, because it seems that a simple game reload does not work (as with control.lua...).

So it works for player.print, but how can I get this translation into my gui for example ? Into a string ? Let say I want to have the title of the buttons or of the frames also translated...
My mods on the Factorio Mod Portal :geek:
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: locale string access from lua

Post by prg »

Code: Select all

player.gui.center.add{type="frame", caption={"my-caption"}}
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: locale string access from lua

Post by binbinhfr »

prg wrote:

Code: Select all

player.gui.center.add{type="frame", caption={"my-caption"}}
Ok. That's a beginning, but let say that I want to display an error message in a gui-label, with a caption like this :

"Objects missing : iron plate, steel plate, iron bar"

of course, the list of objects is subject to change...

my problem is that

Code: Select all

local s = tostring({"error-message"}) .. entity.localised_name
does not seem to work

as far as I understand, localized string are interprated by factorio, in call to print, caption, etc... but not by lua itself.
So can I concatenate a string that would maintain the CFG tags and passed them to the factorio calls ?
My mods on the Factorio Mod Portal :geek:
Post Reply

Return to “Modding help”