User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Localization Formats

04 Dec 2024, 10:50

I'm assuming that this property would need to send an IPropertyNotification for when the language or the title key changed to render correctly?
Exactly, if you plan to update the UI on language changes, then the properties using the localization dictionary need to notify when dictionary changes.
I ended up writing a converter so I could do this in the markup
Thanks for sharing this! it is valuable for other users for sure.
 
garethrobinson
Posts: 11
Joined: 21 Mar 2025, 03:17

Re: Localization Formats

04 Apr 2025, 05:50

I'd like to do something like:
<Label Content={noesis:Loc {Binding TitleKey}} />

But it doesn't seem to work, is there a way to make this work?
We decided not to support that scenario, as the ViewModel could return the localized string directly in the bound property. So instead of using the Loc extension, you would do a normal binding:
<Label Content="{Binding TitleKey"/>
There's a few annoyances that come with not supporting this.

Firstly, it means you need a parallel implementation in code managing the localization, including every single ViewModel in your application being notified of a change in localization so it can update any bound strings.

Secondly, it doesn't play as nicely if you're using Studio, it's a little complex to explain but when you're using Studio you end up with two applications setting data (Studio and your app) and it'd be much easier to have them setting keys and have the final template localize that data rather than doing it upstream in multiple places. It would also allow embedding properly localized static data sets inside the xaml which means you don't have to duplicate data between Studio and your codebase and deal with differences between the design and what runs in app.

Doing something like
<Label Content={noesis:Loc {Binding TitleKey}} />
is about the first thing I tried with localization when attempting to build an a real interface and I was surprised to find there's no way to do it. Maybe there are technical reasons it's not feasible on your end but if it's possible I'd say it would be very handy.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Localization Formats

07 Apr 2025, 13:48

There is a technical limitation to support exactly that, and it is that MarkupExtensions are not DependencyObjects, so you can't resolve a Binding in one of its properties. But one thing we can possible do is expose a different property that stores the binding itself and we internally resolve that binding, something like:
<Label Content="{noesis:Loc BindingKey={Binding TitleKey}}"/>
What do you think of this approach?
 
garethrobinson
Posts: 11
Joined: 21 Mar 2025, 03:17

Re: Localization Formats

09 Apr 2025, 07:20

Yes, it seems to me like that would work!

Who is online

Users browsing this forum: No registered users and 7 guests