Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 字符串.格式多语言不起作用_C#_Localization - Fatal编程技术网

C# 字符串.格式多语言不起作用

C# 字符串.格式多语言不起作用,c#,localization,C#,Localization,以下是我如何使用String.Format显示消息: String.Format(CultureInfo.CurrentCulture, CommonResource.AlreadyExists, PageResource.UserViewModel_EmailId, viewModel.EmailId) AlreadyExists的Sweedish字符串是{0}{1}'Redan Finns AlreadyExists的英文字符串是{0}'{1}'已存在 但信息总是以英语显示。即使我选择

以下是我如何使用String.Format显示消息:

String.Format(CultureInfo.CurrentCulture, CommonResource.AlreadyExists, PageResource.UserViewModel_EmailId, viewModel.EmailId)  
AlreadyExists的Sweedish字符串是
{0}{1}'Redan Finns

AlreadyExists的英文字符串是
{0}'{1}'已存在


但信息总是以英语显示。即使我选择瑞典语作为语言

你的假设是错误的

  • String.Format
    使用区域性参数获取正确的区域性资源
  • CultureInfo.CurrentCulture
    是正确的区域性
  • 为解决这些问题:

  • String.Format
    使用区域性来格式化
    DateTime
    和编号对象
  • “CultureInfo.CurrentCulture”是windows用于格式化日期时间和数字的区域性信息。如果要获取Windows UI区域性,需要使用
    CultureInfo.CurrentUICulture
  • CommonResource.AlreadyExists
    如果windows区域性设置为Sweedish,则应已返回Sweedish字符串。否则,您可能将资源文件设置错误

    有关资源和文化的更多信息,请参见我的答案:

    但是String.Format(CultureInfo.CurrentCulture,CommonResource.Invalid,PageResource.UserViewModel\u EmailId)。这很好用。唯一的区别是我这里没有包含任何运行时值。