Changing localization programmatically

In some scenarios you might want to change your localization file programmatically based on certain runtime criteria. In this case, rather than including the language file directly in the header, you may place it in a runat=server Literal control, e.g.

<head id="Head1" runat="server"> <asp:Literal runat="server" ID="localeLiteral" Text="<script type='text/javascript' src='/js/i18n/grid.locale-en.js'></script>" /> </head>

This will by default use the English locale. From this point on, you can change the language file at any point with server-side code using something similar to this:

string languageFile = ""; switch (currentLanguage) { case "English" : languageFile = "/js/18n/grid.locale-en.js"; break; case "German" : languageFile = "/js/18n/grid.locale-de.js"; break; case "Hebrew" : languageFile = "/js/18n/grid.locale-he.js"; break; } localeLiteral.Text = "<script type='text/javascript' src='" + languageFile + "'></script>";


  Last Updated: 11/13/2009 | © Trirand, 2009