WebSurfer's Home

トップ > Blog 1   |   ログイン
APMLフィルター

日付表示の変更(3)

by WebSurfer 2010年6月6日 16:20

日付の表示が日本向きでないところがもう一箇所見つかりました。

ウィジェットの Month List または Calendar をクリックして選択されたページを表示したとき、タイトルが日付で表示されるのですが、下の写真のように米国向けの表示になります。

Title の日付表示

どうでもよさそうな細かいこととは思いますが、この際徹底的に直すことにしました(笑)。

この Title をレンダリングしているのはブログアプリのルート直下にある Default.aspx.cs の中の DisplayDateRange メソッドです。

その部分を、ブラウザの言語設定が日本語(ja-JP または ja)になっている場合は、"2010年6月6日" の形式で表示されるよう、以下のように修正しました。

private void DisplayDateRange()
{
  // ・・・中略・・・
  if (!string.IsNullOrEmpty(year) && 
      !string.IsNullOrEmpty(month))
  {
    // ・・・中略・・・
    PostList1.Posts = 
     Post.GetPostsByDate(dateFrom, dateTo).ConvertAll(
       new Converter<Post, IPublishable>(
         delegate(Post p) { return p as IPublishable; }));
    // 以下の部分を修正。
    System.Globalization.CultureInfo ci = 
      System.Threading.Thread.CurrentThread.CurrentUICulture;
    if (ci.Name == "ja-JP" || ci.Name == "ja")
    {
      Title = dateFrom.ToString("yyyy年M月");
    }
    else
    {
      Title = dateFrom.ToString("MMMM yyyy");
    }
  }
  else if (!string.IsNullOrEmpty(year))
  {
    // ・・・中略・・・
  }
  else if (!string.IsNullOrEmpty(specificDate) && 
           specificDate.Length == 10)
  {
    // ・・・中略・・・
    PostList1.Posts = 
     Post.GetPostsByDate(dateFrom, dateTo).ConvertAll(
       new Converter<Post, IPublishable>(
         delegate(Post p) { return p as IPublishable; }));
    // 以下の部分を修正。
    System.Globalization.CultureInfo ci = 
     System.Threading.Thread.CurrentThread.CurrentUICulture;
    if (ci.Name == "ja-JP" || ci.Name == "ja")
    {
      Title = date.ToString("yyyy年M月d日");
    }
    else
    {
      Title = date.ToString("MMMM d. yyyy");
    }
  }
  // ・・・中略・・・
}

Tags:

BlogEngine.NET

About this blog

2010年5月にこのブログを立ち上げました。主に ASP.NET Web アプリ関係の記事です。

Calendar

<<  2024年4月  >>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

View posts in large calendar