Page 1 of 1

locale string access from lua

Posted: Sat Apr 23, 2016 8:29 pm
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

Re: locale string access from lua

Posted: Sun Apr 24, 2016 12:23 pm
by binbinhfr
no idea ?

I really wonder how to generate locale translated message errors (or any kind of messages)...

Re: locale string access from lua

Posted: Sun Apr 24, 2016 12:34 pm
by DaveMcW

Code: Select all

player.print({"error-message"})

Re: locale string access from lua

Posted: Sun Apr 24, 2016 5:55 pm
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"

Re: locale string access from lua

Posted: Sun Apr 24, 2016 6:06 pm
by prg
Where exactly did you put that file?

Re: locale string access from lua

Posted: Sun Apr 24, 2016 6:20 pm
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...

Re: locale string access from lua

Posted: Sun Apr 24, 2016 6:23 pm
by prg

Code: Select all

player.gui.center.add{type="frame", caption={"my-caption"}}

Re: locale string access from lua

Posted: Sun Apr 24, 2016 6:58 pm
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 ?