我有需要支持多种文化类型的 ac# 应用程序。我为每种语言制作了一个 resx 文件,更改文化类型会更改我正在使用的 resx 文件。效果很好。现在我有一个客户不喜欢我使用的标签。他们处于 en-US 文化中,我想保持 en-US 的 resx 以及我们大多数客户的方式不变,但是对于这个特定的客户,有没有办法更改他的资源文件虽然仍然是 en-US 的一部分?例如,我可以制作一个“en-US2”resx 文件或类似的文件,然后指向它吗?或者有没有更好的方法来为同一种语言拥有多个不同的 resx 文件?
1583 次
1 回答
0
我用相同的确切想法问了一个类似的问题(在这里)。基本上,C# 旨在与单个 Resources.resx 一起使用,您可以在其中培养它。根据我从所有狩猎中收集到的信息,您有两个选择:将它们全部放在一个文件中(如workerWelcomeText 和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 回答