在jQuery timeago.js中本地化字符串

时间:2021-02-10 10:14:42

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 ?

我正在使用J Query时间来显示像这个网站的日期时间,我有一个元语言网站,我想为en用户显示:1分钟前和fa 1دقیقهقبل。我想在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",

1 个解决方案

#1


1  

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

我找到了解决方案:我使用了一个页面GetLocalisedScript.aspx来提供我的js文件。

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 :

HTML标记:

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

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

并在我的页面中使用以下内容替换标准src:

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

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

现在在我的js文件(JsFileNameWithoutExtension)中,我将更改这样的字符串:

function alert2(val) {
alert("##Translate(MyStringToTranslate)##");
}

#1


1  

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

我找到了解决方案:我使用了一个页面GetLocalisedScript.aspx来提供我的js文件。

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 :

HTML标记:

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

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

并在我的页面中使用以下内容替换标准src:

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

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

现在在我的js文件(JsFileNameWithoutExtension)中,我将更改这样的字符串:

function alert2(val) {
alert("##Translate(MyStringToTranslate)##");
}