Hello, I’m working on a test randomizer that randomizes potential answers, and checks against a scriptable object in order to see whether or not the chosen answer is correct.
In order to do this I need to translate the answer into english to check whether or not it’s in the list.
I know that it’s within GetLocalizedString(step.Text.text, english), but I can’t seem to ever pull back the correct answer.
It appears that I’m having difficulty finding the original TableEntryReference of each entry.
If I’m operating in French, how would I go about looking up the correct table entry reference, if the current entry is randomized and as such, different from the tableentryreference when the application originally started?
I figured it might be something in KeyId, but I’m having a bit of difficulty here. (I’ve searched through the forums extensively but nothing seems to be working with the other solutions I’ve seen).
In an ideal world, my workflow would be:
→ Have the string of the word in French
→ Find the tableReference of this word
→ Return the string of the word in English by using GetLocalizedString
var english = LocalizationSettings.AvailableLocales.GetLocale("en");
var reference = stringEvent.StringReference.GetLocalizedString(step.Text.text, english);```
Hey Karl, sure thing - I'm just trying to convert a french entry to english, but the table reference I have changes due to randomization so I can't use the table reference that the application starts with.
Ok, I think I understand. You want to take the translated value in 1 language and use that to look up the equivalent in another. Doing GetLocalizedString expects the key, not the translated value.
My advice would be to try and use keys in your code, instead of the actual translated values but I would need to see more of the code to really see how that could work. For now you can do something like this:
First get the StringTable for the language you have the value in
Search through the table for the matching entry
Extract the Key from that entry so you can then get the other localized value.
Something like this
var someTextToFind = "Hello World";
var stringTable = LocalizationSettings.StringDatabase.GetTable("My Table");
StringTableEntry foundEntry = null;
foreach(var entry in stringTable.Values)
{
if (entry.LocalizedValue == someTextToFind)
{
// We found the match!
foundEntry = entry;
break;
}
}
if (foundEntry != null)
{
var englishValue = LocalizationSettings.StringDatabase.GetLocalizedString(foundEntry.KeyId);
}