question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In xyzDialog.cs; using new LocalText("<myKey>") not finding key, works with e.g. "Dialogs.YesButton"

See original GitHub issue

Hi JaiQ,

John Ranger here again 😃

I am currently transferring my developed app (which was based on Serene V1.8.20 or so into the newest serene V1.9.9 - because I had some issues with the language switching and also User auth via AD didn’t work. Both are now working fine with V1.9.9) and while doing this, I am also transferring every statically programmed text Output into the localisation Framework.

For this I have put a new json file called ClientAndAssetManagement.invariant.json into xyz.Web/Scripts/site/texts and filled it with key-value pairs.

For most Things this works fine (e.g. I can define DB.xxxx keys (which I first look up within the Translation serenity GUI) and use them in xyzRow.cs) but when I want to use such a DB.xxxx key (which works in xyzRow.cs) or a completely new key (e.g. “Dlg.Stammdaten.CSVDelimiter.Warning.SetDefault”) within xyzDialog.cs to be used within a Q.Confirm popup, the LocalText method does not recognize my custom keys and just Shows the key instead of the desired value.

But… If - within xyzDialog.cs - I Exchange my custom key with a Serenity Default key like “Dialogs.YesButton” then localtext can translate the key into the related value and Outputs “yes”.

I have looked through your Dev-Guide but didn’t find anything special mentioned that custom keys have to be handled differently than Serenity keys.

The Definition within the json Looks like this:


        "Dlg.Stammdaten.CSVDelimiter.Warning.SetDefault": "Warning! Checking this checkbox and clicking on 'update' will set this CSV delimiter as the 'default'.\n\nDo you really intend to do that?",

The code within xyzDialog.cs Looks like this:


                  var warning = new LocalText("Dlg.Stammdaten.CSVDelimiter.Warning.SetDefault");   

                  Q.Confirm(warning.ToString(), () =>
                    {
                        isChecked = true;
                        form.IsDefault.Value = isChecked;
                    }
                    , new ConfirmOptions { DialogClass = "s-MessageDialog s-WarningDialog" });

–> This Outputs: “Dlg.Stammdaten.CSVDelimiter.Warning.SetDefault” instead of the text defined within the json.

Question: How can I use LocalText within xyzDialog.cs to fetch some Txt out of the localization json?

Hint: I have put the whole Content of the Jason file into a json validator (jsoneditoronline.org) and everything seems to be ok with the Content.

Thanks for your help and

with Kind regards,

John

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JohnRangercommented, Feb 12, 2016

Hi JaiQ,

that was it! I have now changed my Dlg. keys to Dialogs. and it immediately worked!

Thanks again for your fast and precise help.

Thanks also to Victor. --> I will have still to find out why my Db. key didn’t work when I tested it on script side (most probably a typing error on my side). But I anyway wanted Dialogs… so that works fine for me now.

Also: I somehow don’t like to use Q… when there is an explicit command so I will stick with the code below. 😃

For reference to other Readers:

In the web.config the relevant block Looks like this (look at the LocalTextPackages entry):

...
 <appSettings>
    <add key="DevelopmentSettings" value="{ IsDevelopmentMode: true }" />
    <add key="LocalTextPackages" value="{ Site: [ 'Controls.', 'Db.', 'Dialogs.', 'Enums.', 'Forms.', 'Permission.', 'Site.', 'Validation.' ] }" />
    <add key="Logging" value="{  File: '~\\App_Data\\Log\\App_{0}_{1}.log',  FlushTimeout: 0,  Level: 'Off' }" />
    <add key="ScriptBundling" value="{ Enabled: false, Minimize: false }" />
    <add key="UploadSettings" value="{ Path: '~\\App_Data\\upload\\' }" />
    <add key="vs:EnableBrowserLink" value="false" />
    <add key="ActiveDirectory" value="{ Domain: 'sc.intra' }" />
  </appSettings>

Here you can see that Dialogs. is one of the key prefixes which are supported by Default by serenity. If you want to have your own key prefixes also transported to the script side, add them here.

On the script side (e.g. within xyzDialog.cs), you can use These texts like this:

                    var warning = new LocalText("Dialogs.Stammdaten.CSVDelimiter.Warning.SetDefault");

                    Q.Confirm(warning.ToLocaleString(), () =>
                    {
                        isChecked = true;
                        form.IsDefault.Value = isChecked;
                    }
                    , new ConfirmOptions { DialogClass = "s-MessageDialog s-WarningDialog" });

With Kind regards,

John

0reactions
volkanceylancommented, Feb 12, 2016

LocalText doesnt send all texts to script side. There is a LocalTextPackages configuration in web.config that contains which texts are sent. This is to limit size as not all texts are used in script. Either start your texts with ones in wen.config Dialogs Forms etc or add your prefix there. Should add a topic about this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MyKey®
The available MyKey feature allows you to configure one or more of your Ford keys to control your vehicle's safety settings, even when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found