Hello, I’m trying realtime data bindings and localization features.
I know how to bind to specific localization key through LocalizedString binding. It works great, but.
Let’s go further. I got the view that has its data source. And I want to assign LocalizedString TableEntryReference (localized key) from that defined data source. I know how to change it from the code or fill that data source with an already localized string (this won’t work if we change the language).
The best would be to have LocalizedString binding the key can be bound from the data source.
I’m not sure I understand. Can you provide more details, maybe an example of what you are trying to do?
Sure,
I want a scriptable object (or other data source) containing localised item names.
Like
SO1
SO2
Those are localised strings in the Unity Localisation package and are translated to
item1Name: Leather Armor
item2Name: Chain Armor
So in Unity Toolkit, I want to have a binding that will take SO1.name value and localize it to Leather Armor
Ok. For this to work you would need to define a converter so it knows how to convert a LocalizedString. The simplest thing to do would be to add another property which is a string that does LocalizedString.GetLocalizedString on the property, then bind against that property.
Does that will detect language change?
No, but you could implement the property changed interface and call that when the locale changed.
Is there any example using that interface?
Thanks,
I’m already using it in some places when I want to auto-update my UI when something is changed. However my concern is that when the user changes the language, I need to update all my properties to get it to work.
@karl_jones Is there anything planned to improve the workflow, at least on the roadmap? It’s not fun to refresh strings manually. Ideally, we should just bind LocalizedStrings directly with automatic locale changes.
Yeah, it’s good for data that never changes(not taking into consideration localized variables here) but it can’t be used for viewModels with dynamic strings. I was talking about using LocalizedStrings with [CreateProperty] directly instead of creating strings.
Can you file a bug report so we can look into it? New tab
It’s not a bug technically, it’s just that you can’t bind localizedStrings using default DataBinding
Here’s example:
[CreateProperty]
public LocalizedString SomeText
{
get;
private set => SetProperty(ref field, value);
} = default!;
When binding like this it will result in bunch of crap like TableEntryReference(some guid etc)
Workaround is to add another property which is a string that does LocalizedString.GetLocalizedString on the property, subscribe to locale changes and refresh string manually. Which is in my opinion is not a good workflow!
Oh yes that’s probably because we need a converter.
Unity - Manual: Create a runtime binding with a type converter
If you file a bug report with an example we can make sure it works how you expect.
Btw this issue got closed. I thought I should mention it here as I don’t know how it affects it’s visibility for you. Shouldn’t name it as a feature request.