Reputation: 599
I have a string "Sunday", i want to change this Polish(Poland) . How can i change. I try to use Iformateprovider
Upvotes: 0
Views: 1060
Reputation: 62012
If you have some DateTime
value dateTime
, then you can use
dateTime.ToString("dddd")
to produce the day-of-week name in the current culture, or
dateTime.ToString("dddd", new CultureInfo("da-DK"))
to produce it in another culture (here Danish (Denmark)).
If you want the "source" of these day names, use
string[] dayNamesPolish = (new CultureInfo("pl-PL")).DateTimeFormat.DayNames;
string[] dayNamesEnglish = CultureInfo.InvariantCulture.DateTimeFormat.DayNames;
To actually translate a string, do this:
string stringToTranslate = "Sunday";
int idx = Array.IndexOf(dayNamesEnglish, stringToTranslate);
string stringResult = dayNamesPolish[idx];
This works even though the FirstDayOfWeek
is not the same in the two cultures (Polish has Monday as the first day).
Upvotes: 1
Reputation: 100630
You need to get `IFormatProvider" from culture you want. I.e.
new System.Globalization.CultureInfo("pl-pl").DateTimeFormat.DayNames[0]; // niedziela
Or to format current DateTime
into just day of the week:
var day = String.Format(
new System.Globalization.CultureInfo("pl-pl"),
"Now:{0:dddd}", DateTime.Now);
Upvotes: 1
Reputation: 17673
see this National Language Support (NLS) API Reference , http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx
Upvotes: 0
Reputation: 121881
Basically, you need a different "resource" for each language:
The "English" resource would contain the word "Sunday", the "Polish" resource the word "niedziela".
Upvotes: 2