[0.12.30] unicode / mod / lua

Things that we don't consider worth fixing at this moment.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

[0.12.30] unicode / mod / lua

Post 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 ?
My mods on the Factorio Mod Portal :geek:
kovarex
Factorio Staff
Factorio Staff
Posts: 8207
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.30] unicode / mod / lua

Post 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.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.12.30] unicode / mod / lua

Post 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.
My mods on the Factorio Mod Portal :geek:
Rseding91
Factorio Staff
Factorio Staff
Posts: 14301
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.12.30] unicode / mod / lua

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.12.30] unicode / mod / lua

Post 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 ?
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: [0.12.30] unicode / mod / lua

Post 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)
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: [0.12.30] unicode / mod / lua

Post 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}
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: [0.12.30] unicode / mod / lua

Post by binbinhfr »

Thanks again, very good and useful tip ! It works perfectly and now I can localized even the whole GUI.
My mods on the Factorio Mod Portal :geek:
Post Reply

Return to “Won't fix.”