I am trying to localize responses of my web api.
I created a Resource file (Messges.resx) in my project containing all the strings that are localized. And using Accept-Language header to identify user's language.
In the responses I can set the string as:
response = Messages.KEY_GOOD_MORNING
which will get the string for that name in language of the current thread culture. I will have to change thread's current culture to the culture found from Accept-Language header. But I don't want to change the culture of the thread since this will also change number/date formatting which is problematic for me.
Another alternative I see is- using ResourceManager and passing the culture as-
Messages.ResourceManager.GetString("KEY_GOOD_MORNING", CultureInfo.CreateSpecificCulture(lang.value))
This way I won't have to change the culture of the thread. But the problem with this approach is- string names aren't type safe anymore. A typo in the string name passed to GetString() may result into null values returned.
Is there any other approach I can adopt to avoid both the problems above?