Question

i am using J Query time ago for showing date time like this site, and i have a metalanguage website, i want to show for en users : 1 min ago and for fa 1 دقیقه قبل . i want to use resource keys in timeago.min.js ?

prefixAgo: null,
    prefixFromNow: null,
    suffixAgo: '<%= Resources.IPortal.Ago %>'//something like this,
    suffixFromNow: "from now",
    seconds: "less than a minute",
    minute: "about a minute",
    minutes: "%d minutes",
    hour: "about an hour",
    hours: "about %d hours",
    day: "a day",
    days: "%d days",
    month: "about a month",
    months: "%d months",
    year: "about a year",
    years: "%d years",
Was it helpful?

Solution

i found solution : i used a page GetLocalisedScript.aspx to serve my js files.

Code behind :

protected void Page_Load(object sender, EventArgs e)
{
    string retval = "";

    string file = Request["JsFileName"].ToString();

    using(StreamReader sr = new StreamReader(Server.MapPath(string.Format("~\\scripts\\{0}.js",file))))
    {
        retval = sr.ReadToEnd();
        sr.Close();
    }

    Regex rx = new Regex("##Translate(.+?)##",RegexOptions.Singleline);
    MatchCollection mc =  rx.Matches(retval,0);
    foreach (Match m in mc)
    {
        string strResxKey = m.Value.Replace("##Translate(", "").Replace(")##", "");
        string val = GetGlobalResourceObject("myResource", strResxKey).ToString();
        retval = retval.Replace(m.Value, val); 
    }
    //Just write out the XML data
    Response.ContentType = "text/xml";
    //NOTE THAT THIS PAGE DOESN'T CONTAIN ANY HTML TAG, WHATSOEVER
    Response.Output.Write(retval);
}

HTML Markup :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetLocalisedScript.aspx.cs" Inherits="TestMulti.GetLocalisedScript" %>

and in my page replaced standard src with something like this :

<script src="GetLocalisedScript.aspx?JsFileName=JsFileNameWithoutExtension" type="text/jscript" ></script>

now in my js file(JsFileNameWithoutExtension) i will change strings like this :

function alert2(val) {
alert("##Translate(MyStringToTranslate)##");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top