1

正しくないリソース ファイルをいくつか削除するまでは正常に機能していた Web サイトがあります。ただし、これが機能しない理由ではない場合があります。基本的に、ほとんどの多言語 Web サイトと同様に、ユーザーはフラグをクリックして言語を変更できます。

    protected void imbEnglish_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("en-GB");
}
protected void imbFrench_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("fr-FR");
}
protected void imbGerman_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("de-DE");
}
protected void imbSpanish_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("es-ES");
}
protected void imbItalian_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("it-IT");
}
protected void imbPolish_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("fr-FR");
}

protected void SetCultureStoreCookie(string culture)
{
    //Sets the cookie that is to be used by Global.asax
    HttpCookie cookie = new HttpCookie("CultureInfo");
    cookie.Value = culture;
    Response.Cookies.Add(cookie);

    //Set the culture and reload the page for immediate effect. 
    //Future effects are handled by Global.asax

    Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

    //Response.Redirect(Request.Path);
    Server.Transfer(Request.Path);
}

コメントにあるように、その後のカルチャの設定は Global.asax で処理されます。

    protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpCookie cookie = Request.Cookies["CultureInfo"];

    if (cookie != null && cookie.Value != null)
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
        Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);
    }
    else
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
    }
}

マスター ページを含むすべてのページには英語 (既定) のリソース ファイルがあり、フランス語のリソース ファイルの作成を開始しました。

リソース ファイル

ただし、フランスの国旗をクリックしても何も起こりません。コードをステップ実行すると、Cookie が設定され、Thread.CultureInfo 行が実行されます。

他に確認すべき場所についてのアイデアはありますか?

ありがとう。

4

1 に答える 1

0

やり方を変えることで解決しました。明らかに、MasterPage クラスには InitializeCulture というメソッドがありません。他の投稿で見たいくつかのヒントを使用して、BaseClass ページを作成しました。

using System;

System.Collections.Generic の使用; System.Linq を使用します。System.Web の使用; System.Threading の使用; System.Globalization の使用;

/// /// Translations の概要説明 /// public class BasePage : System.Web.UI.Page { public BasePage() { // // TODO: ここにコンストラクタ ロジックを追加 // }

protected override void InitializeCulture()
{
    HttpCookie cookie = Request.Cookies["CultureInfo"];

    if (cookie != null && cookie.Value != null)
    {
        //Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
        //Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);

        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cookie.Value);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
    }
    else
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
        //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
    }

    base.InitializeCulture();
}

protected void Page_Load(object sender, EventArgs e)
{
    InitializeCulture();
}

}

次に、BaseClass ページから継承するように各ページを変更しました。

public partial class AboutUs : BasePage

{

}

これで問題は解決しました。

于 2013-03-08T10:05:47.830 に答える