1

What I am trying to do:

I am working on a chat bot service where I have different channels of access. On one channel I want to use my Customer.resx file and on another channel I want to use my Worker.resx file.

The problem:

I know how localization works to switch between Worker.en-US.resx and Worker.es-MX.resx, but I am unsure how to switch from one normal resx file to a completely different context one. These will each be translated into other languages so I can't simply use Customer.en-US.resx and Worker.es-MX.resx as a workaround. I do know that I can build a custom culture using the CultureAndRegionInfoBuilder, but I would rather do this in a simpler way than that, something along the lines of how you do localization. I am currently building custom cultures using this method and I have Resources.worker-en-US.resx and similar for customer, but this is a round-about way and I know there must be a better way.

For clarification I know I can grab a resource file with ResXResourceSet, but the idea was that I would like to have two separate resource files with localization for each (worker.en-US and customer.en-US).

Nox
  • 1,358
  • 1
  • 13
  • 25

1 Answers1

0

I would combine both of these as into one because resx's are really tied to cultures/languages. You can use a strategy pattern to get the right strings at the right time.

interface IStrings { string Foo { get; } }
class WorkerStrings : IStrings { ... }
class CustomerStrings : IStrings { ... }
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • So basically I have to do something like customerWelcomeText and workerWelcomeText in my Resources.resx instead of splitting it out or go a round about way of dealing with this? – Nox Apr 17 '17 at 18:46
  • you could combine them into one or split them, but the implementations would request the right ones and the consumer of `IStrings` would get the right ones depending on the instance. – Daniel A. White Apr 17 '17 at 18:47
  • From everything I found that seems to be my only option. I was thinking it was my inexperience with c# stopping me from figuring it out, but it's apparently impossible the way I wanted to do it. Seems I will have to build out a method that checks the current culture and returns string for expected file. – Nox Apr 17 '17 at 19:10