game.getlocalised_something_ wrong return type

Bugs that are actually features.
Post Reply
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

game.getlocalised_something_ wrong return type

Post by Adil »

As can be tested by command like this

Code: Select all

game.player.print(serpent.block(game.getlocalisedentityname("small-biter")))
	game.player.print(serpent.block(game.getlocaliseditemname("iron-ore")))
	game.player.print(serpent.block(game.getlocalisedtechnologyname("steel-processing")))
getlocalisedentityname, getlocaliseditemname and getlocalisedtechnologyname return tables instead of strings which wiki claims.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: game.getlocalised_something_ wrong return type

Post by rk84 »

Not a bug, but outdated information. Reason why you get just key of localized string in table, would be desyncing of players with different language settings.
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: game.getlocalised_something_ wrong return type

Post by Adil »

Right, I guess there's no reason to do anything fancy with those strings anyway.
I've been updating abandoned mod where guy was concatenating that string to make playermessages instead of using script localisations. Which I can't quite put together in my mind how to use as well. :oops:
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: game.getlocalised_something_ wrong return type

Post by kovarex »

You can still concatanate the localised strings.

I guess it is not really documented well enough (could someone do it?).

The good example is data\scenario-pack\campaigns\tight-spot\lualib\tightspot.lua

Code: Select all

table.add{type="label", caption={"", {"money"}, ":"}, style="caption_label_style"}
table.add{type="label", caption=""}
table.add{type="label", caption={"", {"balance"}, ":"}}
table.add{type="label", caption=debt - available, name="balance"}
table.add{type="label", caption={"", {"required"}, ":"}}
Basically in script:
  • {"string"} means translation of key "string"
  • "string" means the literal "string" without translation
  • {"string", "1"} means translation of key "string" with the first parameter literal 1
  • {"string", {"other_string"} } means translation of key "string" with the first parameter being translation of other_string
  • {"string", {"other_string", {"third string"}} } And the recursion can go on
  • {"", {"string"}, ":", {"some_other_string"}} The translation of "" means simply concatenation of the strings (that can be literals of translations recursivelly again)

User avatar
Mr. Thunder_Tw
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Mon Sep 29, 2014 2:15 pm
Contact:

Re: game.getlocalised_something_ wrong return type

Post by Mr. Thunder_Tw »

kovarex wrote:You can still concatanate the localised strings.
....
Is this only available with the caption of gui-elements?
It works on captions but If I try to use it with string.format or variables I get a table with my key as first entry, even if I use game.localise( "translation-key" ).... Any suggestions on that? Maybe for multiplaye-sync-ing I have to pass the playerindex as a parameter??
Basicly its for a time showing gui element, lots of vars joining in 1 string.
my Mod: ThunderGui

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: game.getlocalised_something_ wrong return type

Post by kovarex »

Mr. Thunder_Tw wrote:
kovarex wrote:You can still concatanate the localised strings.
....
Is this only available with the caption of gui-elements?
It works on captions but If I try to use it with string.format or variables I get a table with my key as first entry, even if I use game.localise( "translation-key" ).... Any suggestions on that? Maybe for multiplaye-sync-ing I have to pass the playerindex as a parameter??
Basicly its for a time showing gui element, lots of vars joining in 1 string.
I probably don't understand your question.

The concatenation (done the special way I just described) can be done in any variable and put on any place that accepts translated string. I don't know what is string.format, but you probably can't use that as you need to keep the specified structure.

User avatar
Mr. Thunder_Tw
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Mon Sep 29, 2014 2:15 pm
Contact:

Re: game.getlocalised_something_ wrong return type

Post by Mr. Thunder_Tw »

string.format(...):

Code: Select all

days = string.format( "%d %s", run_time_days, game.localise("days"))  -- <-- this does not work
--days = string.format( "%d %s", run_time_days, {"days"})  -- <-- this does the same, not good.
...
myFlow.tdlTotal.caption = string.format(
				"%s %dh %dm",				
				days,
				run_time_hours,
				run_time_minutes % 60 )
http://lmgtfy.com/?q=lua+string.format
Basic lua functionality...
kovarex wrote:can be done in any variable and put on any place that accepts translated string.
only works with the caption variable of gui-elements for me.
As is logical. You need to be able to create tables that way, But NOT translations. plz repair game.localise(...) so it gives a string not a table
my Mod: ThunderGui

User avatar
Mr. Thunder_Tw
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Mon Sep 29, 2014 2:15 pm
Contact:

Re: game.getlocalised_something_ wrong return type

Post by Mr. Thunder_Tw »

The problem I see. Is that these translations are only done AFTER your engine detects a table in your gui-element caption. but there is no direct translator function in lua. Game.localise is a fake function. because it transforms the string to a table and nothing more.

Why? I can only see this as a hacked way to translate stuff. True you need to stay in sync on multiplayer games using different translations yet playing together. But in that case I need the ability to translate my string for a specified player by using his playerindex. You guys totaly denied that option...

sorry if my english isn't 100% correct.
my Mod: ThunderGui

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: game.getlocalised_something_ wrong return type

Post by kovarex »

Mr. Thunder_Tw wrote:string.format(...):

Code: Select all

days = string.format( "%d %s", run_time_days, game.localise("days"))  -- <-- this does not work
--days = string.format( "%d %s", run_time_days, {"days"})  -- <-- this does the same, not good.
...
myFlow.tdlTotal.caption = string.format(
				"%s %dh %dm",				
				days,
				run_time_hours,
				run_time_minutes % 60 )
http://lmgtfy.com/?q=lua+string.format
Basic lua functionality...
kovarex wrote:can be done in any variable and put on any place that accepts translated string.
only works with the caption variable of gui-elements for me.
As is logical. You need to be able to create tables that way, But NOT translations. plz repair game.localise(...) so it gives a string not a table
I'm sorry but you don't understand. You can't use format. You can't get localised string, because it is different for different players as they can have different language -> desynchronisation, read more here: https://www.factorio.com/blog/post/fff-53.

User avatar
Mr. Thunder_Tw
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Mon Sep 29, 2014 2:15 pm
Contact:

Re: game.getlocalised_something_ wrong return type

Post by Mr. Thunder_Tw »

not sure if you are ignoring or I'm beeing seriously wrong.
That post clearly states it didn't work because "Factorio installations had different language setup" !
What is there to go desync if both games have the same translated string for the player's chosen language?
Seriously or you are dooing your crc-crafting-checking a little bit too strict or i'm losing it. All games have identical translation-resources, international. Use them identicaly and things go sync-super? Whats 10 MB Ram/Disk-space more for a game like factorio and current gen pc's? Because that could be the only logical issue on the path to glory imho and only in multilingual games.
I mean what do gamers expect? "Oh my game needs 10MB too much for me to play with my [place country here]-friend so im never gonna be able to!"? What is realy holding you back? Why do we mod developers need to learn a wicked way to concatenate strings when there is already a huge wikki on how it should be done(witch you fail to provide for 3 months now). You make logic go boom while creating a logic-thriving application! Blasphemy!! You get my point now I hope, this can however be filed as first world problems tho. My nerd-feels r break; for( i = 1; count to 10 ) puf(air);
my Mod: ThunderGui

Post Reply

Return to “Not a bug”