Forum


HomeHomePremiumPremiumDevelopmentDevelopmentAngularJS resourcekeysAngularJS resourcekeys
Previous
 
Next
New Post
5/15/2015 7:33 AM
 

Hello,

Since I'm building all my lists for drop boxes and table headers in my script I would like to be able to use resource keys in them. My plan is to access my view.ascx.resx from my code behind and load the keys into a object that I can serialize then pass to my javascript in my view. I should then be able to add them to my scope and access them in my controllers. The problem is that I can't seem to figure out how to access the resource files... What I've tried:

I tried using ResourceManager but I couldn't figure out the correct file name / path:

Attempted to use ResXResourceReader but again I couldn't figure out the right file path:

Most recently I tried getting the resource names to hopefully figure out what the correct file path is but all I get is an empty string array...

Any ideas? Thanks.

 
New Post
5/15/2015 8:28 AM
 

Michael,

You may be overthinking this one.  If you have your View.ascx.resx in the App_LocalResources folder,  in your View.ascx.cs code-behind, simply use:

using DotNetNuke.Services.Localization;
...
string localString = Localization.GetString("MyString.Text", LocalResourceFile);
 
New Post
5/15/2015 9:35 AM
 

Thanks.

That definitely works and it's gotten me on the right path towards what I want to do. However I want to retrieve all of the keys and store them in an object for serialization. It would be very very repetitive to have to manually code each resourcekey into a list and keep it updated each time I add a new one. I'll play around with localization and see what I can figure out.

 
New Post
5/15/2015 12:04 PM
 

Alright I made a little progress but then I got stuck... I built a model to hold the resource keys I'm going to serialize:

Then I grabbed all the property names and stored them in a list of strings:

Now I'm trying to build a loop that will go through and add the name to a list of my ResourceKey model and the value aka the text to set... Problem is when I pass a variable to it...

It always comes back null... However:

If I pass a simple string it works just fine. Super confused. I think I may have fried my brain for today.

Ideas? Thanks.

 
New Post
5/18/2015 6:56 AM
 

Happy Monday!

Figured my way around the problem. 

Side note: I'm having an issue in this particular module where for some reason I'm getting errors on my resx file generated by the template where it doesn't like the '.Text' in the name.

Doesn't really seem to hurt anything though annoying still.

Anywho the problem is when I pass a variable to GetString it thinks this contains a string containing text that is the 'Name' WITHOUT the .Text which is a sort of 'type'. This is its behavior by default. Therefore if you pass a string such as 'test.Text' its actually going to look for a string like 'test.Text'.Text (ignore the '' there's just for emphasis).  To fix this I did some regex to get rid of the unnecessary text:

An interesting side note is that '_' and '.' seem to be treated as the same thing. I read that '.' are automatically converted to underscores.

Now I just have to incorporate this into my JS files.

Cheers.

 
Previous
 
Next
HomeHomePremiumPremiumDevelopmentDevelopmentAngularJS resourcekeysAngularJS resourcekeys



Try FREE
30 days money back guaranteed