複数のカルチャ タイプをサポートする必要がある ac# アプリケーションがあります。言語ごとに作成された resx ファイルがあり、カルチャ タイプを変更すると、使用している resx ファイルが変更されます。よく働く。現在、私が使用したラベルが気に入らないクライアントがいます。彼らは en-US カルチャに属しており、en-US の resx を変更せず、ほとんどのクライアントと同じようにしたいと思いますが、この特定のクライアントのリソース ファイルを変更する方法はありますかまだ en-US の一部ですか? たとえば、「en-US2」resx ファイルなどを作成して、それを指すことはできますか? または、同じ言語に対して複数の異なる resx ファイルを持つより良い方法はありますか?
1583 次
1 に答える
0
私はまったく同じアイデアで同様の質問をしました(こちら)。基本的に、C# は単一の Resources.resx で使用することを意図していました。私がすべてのハンティングから収集したものから、2 つの選択肢があります。すべてを 1 つのファイル (workersWelcomeText と employeeWelcomeText など) に入れるか、複数の resx ファイルを作成し、それらを処理して必要なリソース ファイルを返すモデルを構築します。
モデル (必須ではありませんが、推奨事項):
namespace Bot.Models
{
public class Dialog
{
internal static string Name { get; set; }
internal static string Culture { get; set; }
//Returns the rsource file name.culture.resx
internal static string ResourceFile { get { return $"{System.AppDomain.CurrentDomain.BaseDirectory}Properties\\{Name}.
{Culture}.resx"; } }
}
}
ファイルからリソースを取得するメソッドを作成します。
// You can do this in-line, just remember to reset your resex if you change the file
internal static string GetStrRes(string resourceStr)
{
//Gets your resource file
System.Resources.ResXResourceSet resxSet = new System.Resources.ResXResourceSet(Models.Dialog.ResourceFile);
string response = resxSet.GetString(resourceStr);
return response;
}
モデル パラメータを設定するには:
Models.Dialog.Name = "Worker";
Models.Dialog.Culture = "en-US";
モデルを使用するには:
// Returns content of string resource key, same as Resources.workerText
await context.PostAsync(BotUtils.GetStrRes("RES_KEY"));
于 2017-04-19T13:48:14.803 に答える