Last post Oct 03, 2008 07:52 AM by codeyankee
Oct 03, 2008 07:52 AM|codeyankee|LINK
My software has a function to print invoices for all active customers at once. But we have customers from different countries, so they need invoices in their languages. So, every Customer object has CultureInfo property.
Here is one approach to solve the problem:
public static class ResourceHelper
public static ResourceManager ResourceManager = new ResourceManager(
string invoice = ResourceHelper.ResourceManager.GetString(
But the problem is that resources root name string is hardcoded. So if I move resources to another directory or rename them, then I have to change that hardcoded string also, or I get a runtime error.
Another approach is to use Properties.Resources class (which, you know, also can be accessed via Project properties), so I will be able to access localized resources via properties:
string invoice = Properties.Resources.Invoice;
This code will get "invoice" localized string, depending on CurrentThread.CurrentUICulture. But I need to get localized stringd depending on customer's culture, not on current thread UI culture. So, to do this, I have to write the following code, for example:
string GetStringForCustomer(Culture culture, Func<string> resourceFunc)
Properties.Resources.Culture = culture;
string invoice = GetStringForCustomer(customer.CultureInfo, () => Properties.Resources.Invoice);
This code works, of course, but I don't really like the using of lambda-expressions.
So, each approach has its own cons. Which one would you recommend? Why? Or maybe there is another, better approach?
Thank you in advance.