Solved

C# export object to javascript, translate page controls

Posted on 2014-09-27
1
227 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

829 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