Solved

C# export object to javascript, translate page controls

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

743 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

11 Experts available now in Live!

Get 1:1 Help Now