2

我正在开发一个 Windows 应用程序,它使用 WebClient 从 http URL 下载模板。

我必须在报告中实施本地化。应用程序将始终使用默认语言(英语),并且我将有一个变量来保存必须打印报告的语言。报告模板将根据语言下载。每种具有命名约定的语言的报告模板都不同,例如

默认:http ://www.xyz.com/report/report.htm

英语:report.en-US.htm,西班牙语:report.es-ES.htm 葡萄牙语:report.pt-PT.htm

我是否对每种语言都使用 switch..case 或任何其他方式。

4

3 回答 3

1

您可以使用 Globalization 类来获取您当前的文化。试试下面的。

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

string destUri = String.Format("http://www.xyz.com/report/report.{0}.htm", culture);
于 2013-07-04T10:34:43.480 回答
1

如果文件名格式保持不变,您可以这样做

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

这样,它将为您动态创建 URI,并添加相关的语言环境。作为一种快速的方法

public void Uri GetLocalReportUri(string cultureCode)
{  
   return new Uri(String.Format("http://www.xyz.com/report/report.{0}.htm", cultureCode), UriKind.Absolute);
}
于 2013-07-04T10:27:23.977 回答
1

您可以从以下位置获取当前区域性名称

System.Globalization.CultureInfo.CurrentUICulture.Name

或者

System.Web.HttpRequest.UserLanguages

那么你可以按照以下方式做一些事情

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

输出像

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

于 2013-07-04T10:30:22.083 回答