Please override ToString with GetLocalizedString

To reference another localized string from a translation, you have to use {otherString.GetLocalizedString}. In longer cases, this is really messy and confusing for translators.

If you use just {otherString}, you get something like TableReference(3df2f615-d324-6654-8831-aa51448d5624 - GROUP)/TableEntryReference(12036857856 - OTHER_STRING)

Could you please override ToString of the LocalizedString class so that you get the actual localized string instead of the garble? This would simplify so much.

For the time being, I’ve fixed it for my project by inheriting LocalizedString and overriding it myself. Now I just have to remember to use the correct class every time I use it.

Ah, I don’t think that would be a good idea. That garble is really useful when something goes wrong and we added the current version from other user feedback :wink:
.Net describes ToString as Returns a string that represents the current object.
https://docs.microsoft.com/en-us/dotnet/api/system.object.tostring?view=net-6.0
Which is what it currently does. Changing it to do something else is likely to trip people up and cause some strange bugs such as if you wanted to print out a debug string of the LocalizeString and it starts pulling and loading addressables data and throwing errors etc.

Is this a Smart String you are nesting? We have special handling so that you should be able to do {otherString} with a LocalizedString in a Smart String. If it’s not working then please file a bug report so we can fix it.

Fair enough.
I didn’t know it was supposed to work when nesting a smart string. I have to nest it as {otherString.GetLocalizedString} for it to give me the string, instead of substituting it with the … uh… useful garble.

I’ll file a bug report tomorrow. Thanks for the quick response!

1 Like

Thanks.

What is your root localized string? If you add the nested localized string as a persistent variable then it will definitely work. https://docs.unity3d.com/Packages/com.unity.localization@1.3/manual/Smart/Persistent-Variables-Source.html

Well, the nested string is a field on the first parameter to the GetLocalizedString call of the root string:

I have itemFormatter (the root string), which is “{displayName} x{amount}”.
I call it like so:

var label = itemFormatter.GetLocalizedString(item);

item has int amount and LocalizedString displayName as fields.

When I run this, I get the id of displayName, instead of the actual localized string. So now, as a workaround, I have made a CustomLocalizedString that overrides ToString with => GetLocalizedString, which solves the problem.

1 Like