1

How do you localize ASP.NET + javascript + Silverlight?

I would like to be able to include the same texts in different languages in asp.net pages, javascript on the page, and Silverlight objects on the page.

I have tried with the following method, but have no experience with it in practice, and I would like to hear your opinions on it or alternatives:

1) Create a class library (ResourcesTest) and add a resource file (Phrases.resx) with some strings (Hello='Hello'), plus a localized version (Phrases.da.resx: Hello='Hej').

2) Add an empty javascript file (PhrasesHandler.js).

3) In AssemblyInfo.cs do this to allow the texts to be used by javascript/Silverlight:

[assembly: WebResource("ResourcesTest.PhrasesHandler.js", "application/x-javascript")]
[assembly: ScriptResource("ResourcesTest.PhrasesHandler.js", "ResourcesTest.Phrases", "Phrases")]

4) Reference the resource from ASP.NET code-behind (ResourcesTest.Phrases.Hello), or by including the embedded javascript resource in a web page:

<asp:ScriptManager ID="sm1" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="ResourcesTest" Name="ResourcesTest.PhrasesHandler.js" />
    </Scripts>
</asp:ScriptManager>

and then access the texts from javascript (e.g. Phrases.Hello), or from Silverlight via javascript (HtmlPage.Window.Eval("Phrases.Hello")).

I find this method rather complicated, and I worry about handling such a system, but have not found other ways of sharing localized/multi-language resources between ASP.NET, javascript and Silverlight.

Have you? How do you localize ASP.NET + javascript + Silverlight ?

1 Answer 1

1

If they can all accept data in JSON format, use that.

See: Localize Strings in Javascript

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. I think JSON could do it for the client parts (Silverlight and javascript). Thanks for the suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.