I have the following code that generates an invoice line and includes the month a company has used it's coupons:
invoice.InvoiceLine += CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month.Month) + " (" + usedThisMonth + "), ";
My problem is that companies have a company language (in the DB it's saved under the values 1 or 2).
1 means the Dutch Language, 2 is the French language.
How would I edit my line to let the months appear in the corresponding languages?
I guess I need to start by:
if(invoice.CompanyLanguage == 1)
{
invoice.InvoiceLine += CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month.Month) + " (" + usedThisMonth + "), ";
}
else
{
invoice.InvoiceLine += CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month.Month) + " (" + usedThisMonth + "), ";
}
I have only found samples of creating new CultureInfo
objects but not how to assign it programmatically. How would my code need to look like?
Are you asking how to assign a culture to a variable?
int foo = 1; // change as required
var cultureName = foo == 1 ? "nl-NL" : "fr-FR";
var culture = new CultureInfo(cultureName);
Console.WriteLine(culture.DateTimeFormat.GetMonthName(DateTime.Now.Month));
Prints "augustus" for foo = 1
and "août" for all other values of foo
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.