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 ?