I am working on localization of texts across all the 5 projects which together forms the product.
Localization:
So If user is from USA, they will see the product in en-US
, if they are from China they will see the text in ch-CH
.
And I am stuck at below stuff.
Each project will have its OWN bucket of Resx file (file where I am keeping for translations).
Project A - A.en-US.resx file
A.cn-CH.resx file
Project B - B.en-US.resx file
B.ch-CH.resx file
.
.
.
Now I have a Project Common
which gets referenced by all the projects. So What I wrote a singleton
class in Common
public sealed class Translation
{
private static readonly Translation translation = new Translation();
public static Translation GetTranslation { get { return translation; } }
private Translation() { }
static Translation() { }
public string GetTranslatedMessage(string key, CultureInfo culture, string message, string namespace)
{
var rm = new ResourceManager("namespace", Assembly.GetExecutingAssembly());
message = rm.GetString(key, culture);
return message;
}
}
So far so good, As you can see I am using namespace as 4th parameter
with resource manager
so that I can look for the translation in the right project bucket , I just do something like below:
Translation.Translate(key, culture, message, namespace) // singleton class taking in the namespace to find the right bucket
And it works fine.
Question/Problem: But from every project I need to pass the namespace, I mean where ever I call I need to pass the namespace. I am wondering is there any way, I can implicitly tell which bucket each project needs to look into. Can I use Abstract or 2 singleton classes, factory may be?, or something like that. I am newbie so I am not familiar on how to tackle this issue. I just don't want to pass namespace in every call.
Aucun commentaire:
Enregistrer un commentaire