Share via


Localized Deployment for Silverlight

This topic introduces how to localize the deployment of your Microsoft Silverlight-based applications. For example, if you created a Silverlight-based application for a German-speaking audience, you would want them to have a German Web installation prompt with links to a German end-user license agreement and a German privacy statement.

  • Localizing for a Single Language
  • Localizing for Multiple Languages

Localizing for a Single Language

To localize for a single language:

  1. Get the appropriate Silverlight.js file: There are currently dozens of different Silverlight.js files, each corresponding to one of these languages. These JavaScript files are available in the Silverlight SDK. You have to distribute the appropriate Silverlight.js file with your application. For example, if you want to localize your application to Korean, you would get the Korean version of Silverlight.js and reference it from your host HTML page.

  2. Reference the Silverlight.js file appropriately: Change the .js file reference in the HTML head from "Silverlight.js" to "Silverlight.TextID.js" using the text IDs shown in the following table.

    Locale Text ID
    Arabic (Saudi Arabia) ar-SA
    Bulgarian (Bulgaria) bg-BG
    Chinese - Simplified zh-CHS
    Chinese - Traditional zh-CHT
    Croatian (Bosnia, Herzegovina) hr-hr
    Czech (Czech Republic) cs-CZ
    Danish (Denmark) da-DK
    Dutch (Netherlands) nl-NL
    English en-US
    Estonian (Estonia) et-EE
    Finnish (Finland) fi-FI
    French (France) fr-FR
    German (Germany) de-DE
    Greek (Greece) el-GR
    Hebrew (Israel) he-IL
    Hungarian (Hungary) hu-HU
    Italian (Italy) it-IT
    Japanese (Japan) ja-JP
    Korean (Korea) ko-KR
    Latvian (Latvia) lv-LV
    Norwegian (Norway) nb-NO
    Polish (Poland) pl-PL
    Portuguese (Brazil) pt-BR
    Portuguese (Portugal) pt-pt
    Romanian (Romania) ro-RO
    Russian (Russia) ru-RU
    Serbian (Latin, Serbia, Montenegro) sr-latin-cs
    Slovak (Slovakia) sk-SK
    Spanish (Spain) es-ES
    Swedish (Sweden) sv-SE
    Thai (Thailand) th-TH
    Turkish (Turkey) tr-tr
    Ukrainian (Ukraine) uk-UA

    Note   The English Silverlight.js file will still be available for use as "Silverlight.js" to support updates of the file without code modification to your page.

    For example, in the HTML file you use to host your Silverlight-based application, you would update your reference to Silverlight.js to the Japanese version as shown in the following code.

    HTML
    
    

    ... <!-- Reference the localized Silverlight.js file from the HTML page that hosts the Silverlight plug-in. In this example, the Japanese Text ID (ja) is used to reference the Japanese version of Silverlight.js --> <script type="text/javascript" src="silverlight.ja-jp.js"></script> ...

    **Note**   The localized Silverlight.js files use UTF-8 encoding. Therefore, the referring Web page must notify the browser that it is using UTF-8 encoding. This is accomplished using the following line of code below the \

    Localizing for Multiple Languages

    You can reference only a single Silverlight.js file from your HTML host file. Because of this restriction, you will have to dynamically create the reference to the silverlight.js file to deploy for multiple languages from a single HTML host file. For example, the following ASP.NET code automatically detects the language being used by the user and outputs the appropriate script reference.

    ASP .NET
    <%@ Page Language="C#" AutoEventWireup="true" UICulture="auto" Culture="auto" %>
    <%@ import namespace="System.Threading" %>  
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        protected override void InitializeCulture()  {
            // Do something here if you want to handle a language other than the 0th language automatically.       
            base.InitializeCulture();
        }
        protected override void  OnInit(EventArgs e) {
            HtmlHead h = this.Header;
            if (h != null) {
                // Get the uiculture string.
                String uic = Thread.CurrentThread.CurrentCulture.Name;
                
                HtmlGenericControl s = new HtmlGenericControl(HtmlTextWriterTag.Script.ToString());
                s.Attributes.Add(HtmlTextWriterAttribute.Type.ToString(), "text/javascript");
                s.Attributes.Add(HtmlTextWriterAttribute.Src.ToString(), "silverlight." + uic + ".js");
                h.Controls.Add(s);
            }
            base.OnInit(e);
        }
    </script>
    <html xmlns="https://www.w3.org/1999/xhtml" >
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <head runat="server" id="TheHead">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        View Source to see script reference.
        </div>
        </form>
    </body>
    </html> 
    

    If the user views source and the user's current thread is using English, the user will see the following script resource.

    HTML
    ...
    <Script Type="text/javascript" Src="silverlight.en-US.js"></Script>
    ... 
    

    Naturally, you will need to have all the language-appropriate Silverlight.js files available. Using the previous example, you would keep them all in the same directory as the HTML file.

    See Also

    Instantiating a Silverlight Plug-In
    Overviews and How-to Topics