Question

I have a service method that accepts CultureInfo object as a parameter. I want to use it to get correct strings from Resources by the language that was specified. So I have a method on the service like:

public string GetTranslatedString(CultureInfo c)

And on the client I call this method like this:

ServiceReference.GetTranslatedString(CultureInfo.CurrentUICulture);

I've also tried:

ServiceReference.GetTranslatedString((CultureInfo)CultureInfo.CurrentUICulture.Clone());

But it produces incorrect results! The culture info object gets passed as if it was describing culture of PC where the service is, not the culture of the PC where the client is. So if the client has "nl" culture, the server still gets "en" culture! Why? I know how to solve this issue otherwise by passing LCID to the service instead of the object, but I really want to know why the described approach doesn't work.

Was it helpful?

Solution

Try this (just 4 fun):

CultureInfo ci = CultureInfo.CurrentUICulture;
string text = ServiceReference.GetTranslatedString(ci);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top