Question

I am working on a windows application which downloads a template from http URL using WebClient.

I have to implement localization in report. Application will always be in default language(English) and i will have a variable which will hold the language in which report has to be printed. Report template will be downloaded on the basis of language. Report templates are different for each language having naming convention like

default: http://www.xyz.com/report/report.htm

English: report.en-US.htm, Spanish: report.es-ES.htm Portuguese: report.pt-PT.htm

Do i have ti use switch..case for each language or it is possible any other way.

Was it helpful?

Solution

If the filename format will stay same you could do this

string cultureCode = "en-US"; //set current locale    
Uri reportUri = new Uri(String.Format("http://www.xyz.com/report/report.{0}.htm", cultureCode), UriKind.Absolute);

That way it'll dynamically create the URI for you with the relevant locale added. As a quick method

public void Uri GetLocalReportUri(string cultureCode)
{  
   return new Uri(String.Format("http://www.xyz.com/report/report.{0}.htm", cultureCode), UriKind.Absolute);
}

OTHER TIPS

You can use the Globalization class to get your current culture. Try the following.

string culture = System.Globalization.CultureInfo.CurrentCulture.Name;

string destUri = String.Format("http://www.xyz.com/report/report.{0}.htm", culture);

You can obtain the current culture name from

System.Globalization.CultureInfo.CurrentUICulture.Name

or

System.Web.HttpRequest.UserLanguages

so then you can do something along the lines of

string url = string.Format("http://www.xyz.com/report/report{0}.htm", CultureInfo.CurrentUICulture.Name);

which outputs like

http://www.xyz.com/report/report.en-US.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top