Add file to project with name : App_GlobalResources
Create resource files in above folder like as following :
enUS.resx
esEs.resx
--
--ect
write the below code in test.aspx.cs:
-----------------------------------------
protected void Page_PreInit(object sender, EventArgs e)
{
try
{
string SPLanguage = Request.QueryString["SPLanguage"];
string[] arrSPLanguageSplit = SPLanguage.Split('-');
if (arrSPLanguageSplit.Length > 0)
{
string languageNameAfterSplit = arrSPLanguageSplit[0] + arrSPLanguageSplit[1];
if (File.Exists(MapPath(@"~\App_GlobalResources\" + languageNameAfterSplit + ".resx")) == true)
{
HttpContext.Current.Session["resourceFileName"] = languageNameAfterSplit;
}
else {
HttpContext.Current.Session["resourceFileName"] = "enUS";
}
}
else {
HttpContext.Current.Session["resourceFileName"] = "enUS";
}
}
catch (Exception ex)
{
HttpContext.Current.Session["resourceFileName"] = "enUS";
EventLog.WriteEntry("Page_PreInit:resourceFileName", ex.Message, EventLogEntryType.Information);
}
}
write the below code in test.aspx:
--------------------------------------
<script language="javascript" type="text/javascript">
$(document).ready(function ()
{
var TargetSite = '<%= HttpContext.GetGlobalResourceObject(HttpContext.Current.Session["resourceFileName"].ToString(), "TargetSite") %>';
var TargetLibrary = '<%= HttpContext.GetGlobalResourceObject(HttpContext.Current.Session["resourceFileName"].ToString(), "TargetLibrary") %>';
$('#lblTargetSite').text(TargetSite);
$('#lblTargetLibrary').text(TargetLibrary);
});
</script>
UI:
----
<div>
<label id="lblTargetSite" runat="server"></label>
</div>
<br />
<div >
<label id="lblTargetLibrary" runat="server"></label>
</div>
No comments:
Post a Comment