2

I have a c# application that needs to support multiple culture types. I have a resx file made for each language, and changing the culture type changes the resx file i'm using. 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? For example, can i make a "en-US2" resx file or something like that, and point to that? Or is there a better way to have multiple different resx files for the same language?

Phil
  • 1,852
  • 2
  • 28
  • 55
  • 1
    The [CultureAndRegionInfoBuilder](https://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) may be what you're after, but note that the custom culture [has to be registered on the target machine](http://stackoverflow.com/a/17042843/43846) – stuartd Aug 08 '16 at 22:44
  • 1) You may want to use multiple resources for special clients. Like MainResource.resx, MainResource.en-US.resx for everyone and SpecialCase.resx, SpecialCase.en-US.resx for some particular one. 2) or if you control deployment for this particular client you can just swap the resource =) If you really want an answer add more info to your question. – Sergey.quixoticaxis.Ivanov Aug 09 '16 at 00:02
  • Or you can edit right on the client's machine. – Sergey.quixoticaxis.Ivanov Aug 09 '16 at 00:08

1 Answers1

0

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. 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:

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"));
Community
  • 1
  • 1
Nox
  • 1,358
  • 1
  • 13
  • 25