如何本地化 YUI 的日历组件?

发布于 2024-09-17 21:36:26 字数 220 浏览 3 评论 0原文

我在我的网站中使用 YUI 的日历组件。我已将代码作为 Javascript 插入到 ASP 页面中,如 此示例演示。此示例演示如何为一种区域设置(本例中为德语)配置日历组件。我想知道如何根据每个用户的浏览器语言配置日历?

I am using YUI's calendar component in my website. I have inserted the code into an ASP page as Javascript as this example demonstrates. This example shows how to configure the calendar component for one locale (German in this case). What I would like to know is how can I configure the calendar for each user based on the language of their browser?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

腻橙味 2024-09-24 21:36:26

比我的其他答案中显示的更简单的解决方案是使用 ScriptManager 控件的 EnableScriptLocalization 属性

<asp:ScriptManager EnableScriptLocalization="True">
  <Scripts>
    <asp:ScriptReference Name="yui-calendar-localization.js" />
  </Scripts>
</asp:ScriptManager>

这将自动尝试包含脚本的本地化版本,例如 yui-calendar-localization-de-DE.js

An even easier solution than shown in my other answer would be to use the ScriptManager control's EnableScriptLocalization property:

<asp:ScriptManager EnableScriptLocalization="True">
  <Scripts>
    <asp:ScriptReference Name="yui-calendar-localization.js" />
  </Scripts>
</asp:ScriptManager>

This will automatically try to include a localized version of the script, e.g. yui-calendar-localization-de-DE.js.

夜访吸血鬼 2024-09-24 21:36:26

将特定于语言的初始化代码(如您链接到的页面上所示)放入每种语言的单独文件中(例如“yui-calendar-de-DE.js”)。

然后在页面的代码隐藏中,包含正确的包含文件,具体取决于用户的首选语言,例如使用如下内容:

string language = "en-US";
string[] languages = HttpContext.Current.Request.UserLanguages;
if (languages != null || languages.Length > 0)
  language = languages[0];

Page.ClientScript.RegisterClientScriptInclude(
  "yui-calendar-localization",
  ResolveClientUrl("~/scripts/yui-calendar-" + language + ".js")); 

更新:

本地化文件(您应该自己创建)可能如下所示:

// this is yui-calendar-localization-de-DE.js

function initCalendar(cal)
{
  // Correct formats for Germany: dd.mm.yyyy, dd.mm, mm.yyyy
  YAHOO.example.calendar.cal1.cfg.setProperty("DATE_FIELD_DELIMITER", ".");
  YAHOO.example.calendar.cal1.cfg.setProperty("MDY_DAY_POSITION", 1);

  ...

  YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_LONG",
    ["Sonntag", ... "Samstag"]);
}

然后在您的页面,您在其中创建日历,使用该函数来本地化日历:

// create calendar
cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", 
       { LOCALE_WEEKDAYS:"short", 
     START_WEEKDAY: 1, 
     MULTI_SELECT: true 
   } );
// localize it
initCalendar(cal1); 

Put the language specific initialization code (as shown on the page you linked to) into separate files per language (e.g. "yui-calendar-de-DE.js").

Then in the code-behind of your page, include the correct include file, depending on the user's preferred language, e.g using something like this:

string language = "en-US";
string[] languages = HttpContext.Current.Request.UserLanguages;
if (languages != null || languages.Length > 0)
  language = languages[0];

Page.ClientScript.RegisterClientScriptInclude(
  "yui-calendar-localization",
  ResolveClientUrl("~/scripts/yui-calendar-" + language + ".js")); 

Update:

The localization files (which you should create by yourself) might look like this:

// this is yui-calendar-localization-de-DE.js

function initCalendar(cal)
{
  // Correct formats for Germany: dd.mm.yyyy, dd.mm, mm.yyyy
  YAHOO.example.calendar.cal1.cfg.setProperty("DATE_FIELD_DELIMITER", ".");
  YAHOO.example.calendar.cal1.cfg.setProperty("MDY_DAY_POSITION", 1);

  ...

  YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_LONG",
    ["Sonntag", ... "Samstag"]);
}

Then on your page, where you create the calendar, use that function to localize the calendar:

// create calendar
cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", 
       { LOCALE_WEEKDAYS:"short", 
     START_WEEKDAY: 1, 
     MULTI_SELECT: true 
   } );
// localize it
initCalendar(cal1); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文