1

I have an console application which sends audit emails on scheduled basis. In Email both Spanish and English are present.

We are sending audit date also in email. For example: Monday, January 09, 2017. This text also I want to convert to Spanish. Is there any way we can convert English to Spanish with out third party tools?

I'm unable to use resource files to translate because in this case text is dynamic which comes from db and it changes for every email.

prameela rani
  • 223
  • 3
  • 15

3 Answers3

3

you can specify Spanish culture in to string method:

DateTime dt = DateTime.Now;
// Creates a CultureInfo for Spanish
CultureInfo ci = new CultureInfo("es");
var strFormat = "ddd MMM dd,yyyy"; //please use yours format
Console.WriteLine(dt.ToString(strFormat, ci));
Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36
2
using System.Globalization;

var date = DateTime.Parse("Monday, January 09, 2017");
var culture = new CultureInfo("es-ES");
Console.WriteLine(date.ToString("D", culture));

Output

lunes, 9 de enero de 2017
Shreevardhan
  • 12,233
  • 3
  • 36
  • 50
0

If you take a look at the MailMessage.BodyEncoding property, you'll note the following:

The default character set is "us-ascii".

Try changing your encoding before sending:

message.BodyEncoding = Encoding.UTF8;

(I'm assuming you're sending using a System.Net.Mail.MailMessage. If you're using System.Net.Mail.SmtpClient directly, I would recommend switching to using the MailMessage class and passing instances of that to your SmtpClient.

Tushar_G
  • 300
  • 1
  • 9
  • Is there any way to translate dynamic string from English to Spanish. Here, date is mentioned. I need to translate strings. – user4582348 May 25 '18 at 11:39