Solved

C# export object to javascript, translate page controls

Posted on 2014-09-27
1
224 Views
Last Modified: 2014-10-18
Our internal site has about 200 pages on it and each page has anywhere from 20-100 labels(controls) with titles that need translating.

We don’t do any controls in .NET ie. No serve side or runat.

We currently use Resource files with our 5 different languages and pivot off the users language to display the appropriate text/translation.

Looks something like this.


m.LangOutControl = GetLanguage();

    private string GetLanguage()
    {
        return string.Format("{0},{1},{2},{3},{4}",
              InnUtil.GetResourceLabel("plnCopytoNextPeriod", InnEnum.ResourceFile.App2),
              InnUtil.GetResourceLabel("labStrategy", InnEnum.ResourceFile.Common),
              InnUtil.GetResourceLabel("labAction", InnEnum.ResourceFile.Common),
              InnUtil.GetResourceLabel("labMeasure", InnEnum.ResourceFile.Common),
              InnUtil.GetResourceLabel("labIDP", InnEnum.ResourceFile.Common)
             );
    }

Open in new window



}

This returns a string to a JS function on the master page.

    <script type="text/javascript">
        function GetLangControl() { return '<%= LangOutControl %>'; }
    </script>

Open in new window


Then we put it into an object in JS and load populate the TEXT/HTML.

So I want to move this away from resource files and into our DB, create a tool that the owners of the Applications can manage the text/labels etc. by the appropriate language.

First question: Anyone have a different approach that might work for us.

Second question: How do I make my return an object so I don’t have to rely on position. Ie. From C# my return is this:

{
Lbl: “First Label”,
Lbl2: “Second label”
}

Open in new window

0
Comment
Question by:skillilea
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40348152
I believe this page answer your question : http://msdn.microsoft.com/en-us/library/bb412179(v=vs.110).aspx
So mainly the goal to create a DataContract which define your object with DataMember (which can be based on other DataContract) and use DataContractJsonSerializer to create this Javascript object
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript create file issue 4 45
JavaScript export function not working in IE 15 31
Entity Framework 7 28
Javascript and Jquery not firing 9 37
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now