0

The following is how I am using String.Format to display message :

String.Format(CultureInfo.CurrentCulture, CommonResource.AlreadyExists, PageResource.UserViewModel_EmailId, viewModel.EmailId)  

Sweedish string for AlreadyExists is {0} '{1}' Redan Finns
English string for AlreadyExists is {0} '{1}' already exists

But message is always displayed in English. Even if I select Swedish as the language.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nitish
  • 13,845
  • 28
  • 135
  • 263

1 Answers1

0

Your assumption is wrong.

  1. String.Format uses the culture parameter to get the right culture resource.
  2. CultureInfo.CurrentCulture is the right culture.

To address those:

  1. String.Format uses culture to format DateTime and number objects.
  2. 'CultureInfo.CurrentCulture' is the culture info that windows uses to format DateTime and numbers. If you want to get your Windows UI culture you need to use CultureInfo.CurrentUICulture.

CommonResource.AlreadyExists should already return the Sweedish string if your windows culture is set to Sweedish. If not, you might have set the resource files wrong.

See those of my answers for more on Resources and cultures:

Community
  • 1
  • 1
SynerCoder
  • 12,493
  • 4
  • 47
  • 78
  • But String.Format(CultureInfo.CurrentCulture, CommonResource.Invalid, PageResource.UserViewModel_EmailId). This is working fine. The only difference is I am not concatinating any runtime value here. – Nitish Oct 24 '13 at 09:13