Page 1 of 1

game.getlocalised_something_ wrong return type

Posted: Thu Jan 29, 2015 7:09 pm
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.

Re: game.getlocalised_something_ wrong return type

Posted: Thu Jan 29, 2015 7:27 pm
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.

Re: game.getlocalised_something_ wrong return type

Posted: Thu Jan 29, 2015 8:58 pm
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:

Re: game.getlocalised_something_ wrong return type

Posted: Fri Jan 30, 2015 12:21 pm
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)

Re: game.getlocalised_something_ wrong return type

Posted: Tue Apr 14, 2015 6:59 pm
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.

Re: game.getlocalised_something_ wrong return type

Posted: Wed Apr 15, 2015 5:31 am
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.

Re: game.getlocalised_something_ wrong return type

Posted: Wed Apr 15, 2015 11:18 am
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

Re: game.getlocalised_something_ wrong return type

Posted: Wed Apr 15, 2015 11:44 am
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.

Re: game.getlocalised_something_ wrong return type

Posted: Wed Apr 15, 2015 6:53 pm
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.

Re: game.getlocalised_something_ wrong return type

Posted: Thu Apr 16, 2015 12:49 am
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);