Get ResourceString code behind

I set up localization like in the localization example.
Now I need to retrieve some ResourceString code behind.
Is that possible?

Please show some code to explain what you’ve tried so far, and try to explain a little better what it is that you want to achieve.

So, here is an example:

A separate resource file Resources.ux with the following content:

<ResourceContainer ux:Name="resAll">
    <ResourceString Key="keyText1" Value="Hello" />
    <ResourceString Key="keyText2" Value="world!" />
</ResourceContainer>

and the MainView.ux like this:

<App>
    <Panel >
        <JavaScript>
            var Observable = require('FuseJS/Observable');
            var text2 = Observable('');

            text2.value = resAll.getValue('keyText2');

            module.exports = {
                text2: text2
            };

        </JavaScript>
        <StackPanel Alignment="Center">
            <Text Alignment="Center" Value="{Resource keyText1}"></Text>
            <Text Alignment="Center" Value="{text2}"></Text>
            
        </StackPanel>
    </Panel>
</App>

Line 7 is not working.
The question is: how to retrieve resource strings in code?

In short, you can’t do that. Resources defined in UX live in UX. Why do you need to read them in JS in the first place; what’s the use-case?

As far as localisation goes, we suggest using this approach, which, incidentally, will give you access to the strings in JavaScript.

Upps, I overlooked that approach. I followed this one.

The usecase is: let’s say you retrieve data from an external service and want to react to no data. I that case you will show something like “No data found”. There are two solutions: have a UX switch to show the text if count is zero, or load the text in code behind and display it. I would prefer the second solutions because it belongs to the business logic (javascript) and more important thing of different errors which will then end in an “monster” UX switch to display the different error messages.

Alright, go with the approach I linked then. I imagine adding some lazy-loading wouldn’t be that hard.

Hey SvenWS,
Could you please show me how you solved the Problem?
I also use the Localization in your Link, but dont know how to get the right String in the right language in Javascript…
Please help!
Thanks :slight_smile:

Hi Treviz,

for know I skipped the task. I will follow up in the next four weeks. I think there were some changes in the last releases to exchange between XAML and javascript. But I don’t remember these extensions at the moment. If it’s still not possible I will take Uldis proposal.

Tnaks for your reply!
Actually I havent seen any implementation for this. Maybe here is Someone reading this and can tell me about this :smiley:
Uldis proposal sets the right language String but there is no access to a String from Javascript I think :speak_no_evil:

As you wrote before, I dont want for each message a ux panel. Just want to update the Text inside that Message-Panel…
I Think therefore I have to wait :sweat_smile: