Page 1 of 1

[0.12.30] unicode / mod / lua

Posted: Fri Apr 22, 2016 10:07 pm
by binbinhfr
I don't know wether it is a bug, but it is strange.
In a gui/textfield, you can type unicode caracters (like é è à). But if you get the text in a lua string, and then try to print it in the console, unicode cars are displayed but the string length is longer than expected. And they do not seem to be managed by the lua string lib (for example if I try to extract car by car using string.sub(s,i,i) ).

An explanation ? Or a hint or a turnaround ?

Re: [0.12.30] unicode / mod / lua

Posted: Mon Apr 25, 2016 9:03 am
by kovarex
Lua doesn't suport unicode by default.

More info on this link (http://lua-users.org/wiki/LuaUnicode).

It would be probably possible to use custom lua code to do string operations on unicode strings though.

Re: [0.12.30] unicode / mod / lua

Posted: Mon Apr 25, 2016 9:15 am
by binbinhfr
Thanks for your answer Kovarex.

I'll give a try to UTF-8.lua functions.

I am in the locale stuff these days. I asked more questions on localization ) :
viewtopic.php?f=25&t=24144
and
viewtopic.php?f=25&t=24145

I really think that localization is a good thing to spread Factorio all over the world :-) as a lot of user do not speak english, but a lot of users want to try mods.
So if not existing, you should add a few API functions that give access to localization.
A LUAplayer.get_localized_string( cfg_tag ) would be nice, that would read into the locale cfg file.
I noticed also that there is no localised_name variable on the LUArecipe.

Re: [0.12.30] unicode / mod / lua

Posted: Tue Apr 26, 2016 5:31 am
by Rseding91
binbinhfr wrote:Thanks for your answer Kovarex.

I'll give a try to UTF-8.lua functions.

I am in the locale stuff these days. I asked more questions on localization ) :
viewtopic.php?f=25&t=24144
and
viewtopic.php?f=25&t=24145

I really think that localization is a good thing to spread Factorio all over the world :-) as a lot of user do not speak english, but a lot of users want to try mods.
So if not existing, you should add a few API functions that give access to localization.
A LUAplayer.get_localized_string( cfg_tag ) would be nice, that would read into the locale cfg file.
I noticed also that there is no localised_name variable on the LUArecipe.
The "print" method already supports exactly that - you give it a table with the key and parameters it has if any and it prints it localized. Most things that reach the display support this format.

Re: [0.12.30] unicode / mod / lua

Posted: Tue Apr 26, 2016 7:12 am
by binbinhfr
Rseding91 wrote: The "print" method already supports exactly that - you give it a table with the key and parameters it has if any and it prints it localized. Most things that reach the display support this format.
Several persons claims it is simple, but bould you be more precise and help me on a simple example :

let say that I want to change the caption of a GUI label, so that it concatenates a fixed localized string prefix-message = "Inventory is missing entity" and the localized name of an entity ent.localised_name.

gui.caption = "{\"prefix-message\"}" .. ent.localised_name does not seem to work....

what should I exactly put into my cfg file and in my control.lua ?

Re: [0.12.30] unicode / mod / lua

Posted: Tue Apr 26, 2016 7:50 am
by prg

Code: Select all

prefix-message=Inventory is missing entity __1__

Code: Select all

gui_element.add{type="label", caption={"prefix-message", entity.localised_name}}
(You don't have entities in your inventory BTW)

Re: [0.12.30] unicode / mod / lua

Posted: Tue Apr 26, 2016 9:59 am
by binbinhfr
prg wrote:

Code: Select all

prefix-message=Inventory is missing entity __1__

Code: Select all

gui_element.add{type="label", caption={"prefix-message", entity.localised_name}}
(You don't have entities in your inventory BTW)
For entities in inventory, it was just a stupid example :-)

But for the rest, thank you !!! I'll test this this evening at home.
I suppose that it is also working if I later write the caption separately ?

Code: Select all

gui_element.gui_label.caption={"prefix-message", itemProto.localised_name}

Re: [0.12.30] unicode / mod / lua

Posted: Wed Apr 27, 2016 9:48 am
by binbinhfr
Thanks again, very good and useful tip ! It works perfectly and now I can localized even the whole GUI.