prameela rani
prameela rani

Reputation: 223

Translate dynamic text from english to spanish in dotnet

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.

Upvotes: 1

Views: 2767

Answers (3)

Tushar_G
Tushar_G

Reputation: 300

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.

Upvotes: 0

Shreevardhan
Shreevardhan

Reputation: 12641

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

Upvotes: 2

Victor Leontyev
Victor Leontyev

Reputation: 8736

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));

Upvotes: 3

Related Questions