Localization Question using Loc Extension
Hi,
I've just started using Loc Extension, mostly using the localization sample in the tutorials to guide my progress. A couple questions came up for me:
First, for debugging purposes, I'd like to be able to switch the language being used during runtime. When I do this, none of the existing strings that were displayed using the loc extension change to the new language, but as new screens/pages come in, they are showing the new language. Am I doing something wrong? Or am I missing something? Or is there a way to force the xaml to re-lookup all the strings? It seems like a dependency somewhere hasn't been tripped.
Second, again for debugging purposes, I'd like to be able to reload all the localized text from a file on disk. This changes the iteration time from hours to seconds for someone who is testing localization. However, I'm not quite sure how to do this in XAML. Right now, just like the sample, I'm binding the localized text to a resource dictionary like this:
I have all the keys and the strings. Is there a way for me to dynamically update the resource dictionary? Or, going even further - is there a way for me to just create the localized resource dictionary at runtime and manually bind it to loc extension - and then when I want to change things (either switching languages, or even just updating the strings from a file on disk), I just update the resource dictionary?
it seems like this should be possible, as I can create a resource dictionary using noesis APIs:
https://www.noesisengine.com/docs/Gui.C ... onary.html
I'm just not exactly sure how to bind it to the loc extension. Looking at the docs for loc extension:
https://www.noesisengine.com/docs/App.A ... nsion.html
It seems like I can only bind it to a URI source. But when I open up the source code, it looks like there is a "ResourcesProperty" and I could perhaps just call SetValue() with a resource dictionary directly.
Any advice would be greatly appreciated.
thanks!
sam
I've just started using Loc Extension, mostly using the localization sample in the tutorials to guide my progress. A couple questions came up for me:
First, for debugging purposes, I'd like to be able to switch the language being used during runtime. When I do this, none of the existing strings that were displayed using the loc extension change to the new language, but as new screens/pages come in, they are showing the new language. Am I doing something wrong? Or am I missing something? Or is there a way to force the xaml to re-lookup all the strings? It seems like a dependency somewhere hasn't been tripped.
Second, again for debugging purposes, I'd like to be able to reload all the localized text from a file on disk. This changes the iteration time from hours to seconds for someone who is testing localization. However, I'm not quite sure how to do this in XAML. Right now, just like the sample, I'm binding the localized text to a resource dictionary like this:
Code: Select all
noesis:Loc.Source="{Binding SelectedLanguage.Source}"
it seems like this should be possible, as I can create a resource dictionary using noesis APIs:
https://www.noesisengine.com/docs/Gui.C ... onary.html
I'm just not exactly sure how to bind it to the loc extension. Looking at the docs for loc extension:
https://www.noesisengine.com/docs/App.A ... nsion.html
It seems like I can only bind it to a URI source. But when I open up the source code, it looks like there is a "ResourcesProperty" and I could perhaps just call SetValue() with a resource dictionary directly.
Any advice would be greatly appreciated.
thanks!
sam
Re: Localization Question using Loc Extension
Hi Sam,
On your first issue, uses of LocExtension automatically update their values when Loc.Source is changed. Are you able to reproduce this issue in our Localization example? I have checked it here and it's working fine.
On your second question, the LocExtension.ResourcesProperty dependency property is set to private. You can create your own copy of LocExtension.cs (located in the the NoesisGUI Unity package at Runtime\API\Localization\LocExtension.cs) and set ResourcesProperty to public. This would allow you to access it for use with SetValue(), to set a ResourceDictionary which you have loaded/generated. You can load a ResourceDictionary from disk, at runtime, using Noesis.GUI.LoadXaml() or Noesis.GUI.ParseXaml().
On your first issue, uses of LocExtension automatically update their values when Loc.Source is changed. Are you able to reproduce this issue in our Localization example? I have checked it here and it's working fine.
On your second question, the LocExtension.ResourcesProperty dependency property is set to private. You can create your own copy of LocExtension.cs (located in the the NoesisGUI Unity package at Runtime\API\Localization\LocExtension.cs) and set ResourcesProperty to public. This would allow you to access it for use with SetValue(), to set a ResourceDictionary which you have loaded/generated. You can load a ResourceDictionary from disk, at runtime, using Noesis.GUI.LoadXaml() or Noesis.GUI.ParseXaml().
Re: Localization Question using Loc Extension
Hi Sam,
There is no need to create a copy of LocExtension.cs, Hot Reloading will allow you to see any changes in a Loc.Source ResourceDictionary. Right now you need to change Loc.Source in order to update the UI with the Hot Reloaded values. We need to remove this limitation, could you please create a ticket for this?
There is no need to create a copy of LocExtension.cs, Hot Reloading will allow you to see any changes in a Loc.Source ResourceDictionary. Right now you need to change Loc.Source in order to update the UI with the Hot Reloaded values. We need to remove this limitation, could you please create a ticket for this?
Re: Localization Question using Loc Extension
Hi,
Thanks for the help.
thanks,
sam
Thanks for the help.
I can certainly try this, I'm just not sure how to get to the "LocExtension" object from my UserControl. Is there a way to get that?On your second question, the LocExtension.ResourcesProperty dependency property is set to private. You can create your own copy of LocExtension.cs (located in the the NoesisGUI Unity package at Runtime\API\Localization\LocExtension.cs) and set ResourcesProperty to public. This would allow you to access it for use with SetValue(), to set a ResourceDictionary which you have loaded/generated. You can a ResourceDictionary from disk, at runtime, using Noesis.GUI.LoadXaml() or Noesis.GUI.ParseXaml().
thanks,
sam
Re: Localization Question using Loc Extension
To answer my own question - I think the implication was that instead of binding to Source I instead bind directly to the "ResourcesProperty".I can certainly try this, I'm just not sure how to get to the "LocExtension" object from my UserControl. Is there a way to get that?
I will give this a try.
thanks,
Sam
Re: Localization Question using Loc Extension
So I gave this a shot - I basically made the "ResourcesProperty" public and then bound to that:On your second question, the LocExtension.ResourcesProperty dependency property is set to private. You can create your own copy of LocExtension.cs (located in the the NoesisGUI Unity package at Runtime\API\Localization\LocExtension.cs) and set ResourcesProperty to public. This would allow you to access it for use with SetValue(), to set a ResourceDictionary which you have loaded/generated. You can a ResourceDictionary from disk, at runtime, using Noesis.GUI.LoadXaml() or Noesis.GUI.ParseXaml().
Code: Select all
noesis:Loc.Resources="{Binding SelectedLanguage.Resources}"
Would it be possible for Noesis to just make the Resource property public so I could bind to it? Or is there a good reason to keep it private?
thanks,
sam
Re: Localization Question using Loc Extension
This isn't about hot-reloading in editor, it's about being able to hot-reload for us in a player build, which I would not expect y'all to support. I can give a broader description of our use case if you'd like.There is no need to create a copy of LocExtension.cs, Hot Reloading will allow you to see any changes in a Loc.Source ResourceDictionary. Right now you need to change Loc.Source in order to update the UI with the Hot Reloaded values. We need to remove this limitation, could you please create a ticket for this?
thanks,
sam
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: Localization Question using Loc Extension
Hi Sam,
We've been looking at our current implementation of the Loc extension and as you noticed there is something we have missing. The extension should be able to detect changes in the localization dictionary, and update the target properties automatically. This mechanism is similar to what DynamicResource is already doing, so it should be feasible.
This in combination with the hot-reload (which works in the Editor and also in Player builds with 'Development Build' flag enabled) will make it possible to modify the strings and resources in the language dictionary at runtime and see the changes in the UI in real time. Is this what you want to achieve?
We've been looking at our current implementation of the Loc extension and as you noticed there is something we have missing. The extension should be able to detect changes in the localization dictionary, and update the target properties automatically. This mechanism is similar to what DynamicResource is already doing, so it should be feasible.
This in combination with the hot-reload (which works in the Editor and also in Player builds with 'Development Build' flag enabled) will make it possible to modify the strings and resources in the language dictionary at runtime and see the changes in the UI in real time. Is this what you want to achieve?
Re: Localization Question using Loc Extension
I think that would cover my use cases. Do you know when you might be able to provide this?We've been looking at our current implementation of the Loc extension and as you noticed there is something we have missing. The extension should be able to detect changes in the localization dictionary, and update the target properties automatically. This mechanism is similar to what DynamicResource is already doing, so it should be feasible.
This in combination with the hot-reload (which works in the Editor and also in Player builds with 'Development Build' flag enabled) will make it possible to modify the strings and resources in the language dictionary at runtime and see the changes in the UI in real time. Is this what you want to achieve?
As I mentioned, by making the "Resources" property public, I can already do all of this at runtime -- strings updating and everything -- it's just that in the blend designer it doesn't recognize that property as public. So if you just wanted to make that property public, that would also solve all my use cases. I just mention that because it seems like it might be less work overall for you (I think it's only changing 2 lines of code on your end).
thanks,
sam
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: Localization Question using Loc Extension
Not for the upcoming version, probably next one.Do you know when you might be able to provide this?
I think there is no problem on making that property public in the extension as it is only for Blend, so I generated a new Noesis.GUI.Extenssion NuGet (version 3.0.22) with that change.by making the "Resources" property public
Could you give it a try?
Who is online
Users browsing this forum: No registered users and 10 guests