How to properly display LocalizedString at runtime?

So I’ve successfully localized “static” UI text (i.e. strings that I’ve added to my game before gameplay starts and that don’t change) but I’m having issues with strings that are handled dynamically. For context, I’m making a medical sim and I have a list of patients that are available during a game day. These patients are chosen randomly from a scriptable object list of possible patients. Each scriptable object has different symptoms (which is what I’m trying to localize) that I’ve defined as localized strings. Then, on the patient list script I’ve added this line:

symptoms.text = "Symptoms: " + patient.symptoms.GetLocalizedString() + “.”;

However, when I play the game all that’s displayed is a very long text along the lines of "TableReference(long id string)/TableEntryReference(long id string).

How can I properly display my patient’s symptoms?

Thanks in advance.

That sounds like you are doing ToString on the localized string and not GetLocalizedString.

I would avoid doing
"Symptoms: " + patient.symptoms.GetLocalizedString() + “.”;

The sentence will change with some languages and Symptoms is not localized. I would suggest turning it into a smart string.

For example
“Symptoms: {patient.symptoms}>”

You were correct. I was doing GetLocalizedString on another area of my code but not on the one I was testing. I will also look into smart strings since it’s my first time localizing a game and I’m not super familiar with how they work. Thank you so much for your help!

1 Like

I’ve been looking into smart strings but for the life of me I cannot figure out how to properly show the symptoms list. Right now I’ve arrived at this:

string localizedSymptoms = LocalizationSettings.StringDatabase.GetLocalizedString("PatientInfoTable", "symptomsList");
(localizedSymptoms["symptoms"] as StringVariable).Value = patient.ShownSymptoms;
patientSlotObject.Symptoms.text = localizedSymptoms;

But I keep getting this error:
error CS1503: Argument 1: cannot convert from ‘string’ to ‘int’

and I have no idea what it is that’s expecting an integer here. What am I doing wrong?

You need to use a LocalizedString instead of directly accessing the string database.
https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/Scripting.html

So how would I go about accessing the table entry that contains the value “Symptoms: {symptoms}.” in different locales without accessing the database?

With the localized string class.
There’s examples here Class LocalizedString | Localization | 1.4.5

If you add a public LocalizedString field then you can configure the variable and table reference in the inspector.

With the localized string class.
There’s examples here Class LocalizedString | Localization | 1.4.5

If you add a public LocalizedString field then you can configure the variable and table reference in the inspector.

2 Likes

That did it. Thank you so much for your help and quick replies!

1 Like