Hello,
Im stuck with how to get a localised name of an item.
local realName = game.item_prototypes[itemName].localised_name
gives something like: "item-name.sand"
But how to get the real localised string "Sand"?
Trying to find this out for hours now
How to get localised string?
Re: How to get localised string?
Im really stuck with this.
Found that there is a async method:
local stringRealName = player.request_translation(realName)
returning true.
But the answer is never comming. Any idea why? Any tipp to do this syncron?
local function entities_translated(event)
print("Translated")
end
script.on_event({defines.on_string_translated}, function(event)
entities_translated(event)
end)
Need it only for GUI to filter a list of items with a custom filter.
So no Locale/Desync issues in this spot.
Please help to get the real translated string.
Found that there is a async method:
local stringRealName = player.request_translation(realName)
returning true.
But the answer is never comming. Any idea why? Any tipp to do this syncron?
local function entities_translated(event)
print("Translated")
end
script.on_event({defines.on_string_translated}, function(event)
entities_translated(event)
end)
Need it only for GUI to filter a list of items with a custom filter.
So no Locale/Desync issues in this spot.
Please help to get the real translated string.
Re: How to get localised string?
There is not one localised string, but an array of strings -- one for each language that has been localised. The game knows what locale you've selected and picks the correct string from that array (if a localisation exists).
If you want to print out a localized string, do something like this:
Code: Select all
game.print({realName})
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: How to get localised string?
I need it in a string variable. Found no function doing this.
So currently I use "local stringRealNameBool = player.request_translation(realName)" for all elements on startup and write it in "local function entities_translated(event)" in a global array. Then use this array for translation.
Really really bad - but only thing working i found so far.
Creating a own translation array, because there is no access to the already existing once.
So currently I use "local stringRealNameBool = player.request_translation(realName)" for all elements on startup and write it in "local function entities_translated(event)" in a global array. Then use this array for translation.
Really really bad - but only thing working i found so far.
Creating a own translation array, because there is no access to the already existing once.
Code: Select all
script.on_event(defines.events.on_marked_for_deconstruction, function(event)
entities_marked_for_deconstruction(event)
end)
local function entities_translated(event)
if not global.translatedItems then
global.translatedItems ={}
end
local toTranslateString = event.localised_string[1]
local translatedString = event.result;
if not global.translatedItems[toTranslateString] then
global.translatedItems[toTranslateString] = translatedString
end
end
script.on_event(defines.events.on_string_translated, function(event)
entities_translated(event)
end)
Re: How to get localised string?
Why do you need it as a string?
Re: How to get localised string?
Filtering elements in the GUI for substring search of items.
Its a custom GUI - a list with hundrets of items.
Display the name is not a problem, because the widget ist doing the translation.
But Searching for the displayed string ist hard, because you can not read this localised string anywhere.
Its a custom GUI - a list with hundrets of items.
Display the name is not a problem, because the widget ist doing the translation.
But Searching for the displayed string ist hard, because you can not read this localised string anywhere.
Re: How to get localised string?
Searching localized name is a lot more involved than searching the name.
Raiguard already made a framework doing that see https://github.com/raiguard/Factorio-Ra ... ranslation
Word of warning though. We are currently in the process of merging libraries into one community library. Expect the individual libraries to be deprecated soon™.
Raiguard already made a framework doing that see https://github.com/raiguard/Factorio-Ra ... ranslation
Word of warning though. We are currently in the process of merging libraries into one community library. Expect the individual libraries to be deprecated soon™.
My Mods: mods.factorio.com
Re: How to get localised string?
Have a working solution - by building my own dictionary on startup with async call.
Then search with this:
Only for interest, what is "more involved" then comparing the strings in this pre-build dictionary?
Interesting would be:
- Any chance to get the live translation data without building and using a dictionary?
Dont geht the reason why the mod-API is hiding those strings...
read all the threads regarding desync in multiplayer, but function still should be able to be used in GUI classes by developers knowing what they do.
Then search with this:
Code: Select all
if string.find( string.lower(stringRealName), string.lower(frame.fastfiltertext.text) ) then
Interesting would be:
- Any chance to get the live translation data without building and using a dictionary?
Dont geht the reason why the mod-API is hiding those strings...
read all the threads regarding desync in multiplayer, but function still should be able to be used in GUI classes by developers knowing what they do.