简体   繁体   English

1个文化的多个resx文件

[英]multiple resx files for 1 culture

I have ac# application that needs to support multiple culture types. 我有一个需要支持多种文化类型的ac#应用程序。 I have a resx file made for each language, and changing the culture type changes the resx file i'm using. 我有一个为每种语言编写的resx文件,更改文化类型会更改我正在使用的resx文件。 Works great. 效果很好。 Now i have a client that doesn't like the labels I've used. 现在我的客户端不喜欢我用过的标签。 They are in the en-US culture, and I'd like to keep the resx for en-US unchanged and the way it is for most of our clients, but for this one particular client, is there a way to change his resource file WHILE STILL being part of en-US? 他们属于美国文化,我想保持en-US的resx不变,以及它对大多数客户的态度,但对于这个特定的客户,有没有办法改变他的资源文件虽然仍然是en-US的一部分? For example, can i make a "en-US2" resx file or something like that, and point to that? 例如,我可以制作一个“en-US2”resx文件或类似的东西,并指出这一点? Or is there a better way to have multiple different resx files for the same language? 或者是否有更好的方法为同一种语言提供多个不同的resx文件?

I had asked a similar question with the same exact idea (here.) Basically C# was meant to be used with a single Resources.resx where you culture it out. 我曾用同样的想法问过一个类似的问题(这里)。基本上C#意味着与一个Resources.resx一起使用,你可以将它培养出来。 From what I have gathered from all of my hunting around you have two choices: put it all in one file (like workersWelcomeText and employeeWelcomeText) or create multiple resx files and construct a model to handle them and return the resource file you need: 根据我从所有狩猎中收集到的内容,您有两种选择:将其全部放在一个文件中(如workersWelcomeText和employeeWelcomeText)或创建多个resx文件并构建模型来处理它们并返回所需的资源文件:

Model (not necessary, but good practice): 模型(不是必需的,但是很好的做法):

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"; } }
    }
}

Construct a method to retrieve your resource from the file: 构造一个从文件中检索资源的方法:

    // 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;
    }

To set the model params: 设置模型参数:

Models.Dialog.Name = "Worker";
Models.Dialog.Culture = "en-US";

To consume the model: 要使用该模型:

// Returns content of string resource key, same as Resources.workerText
await context.PostAsync(BotUtils.GetStrRes("RES_KEY"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM