We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Localization of MhtMessageFormatter

Hi,

We have a requirement from our customer to localize From, Sent, To, Subject… words in message header.
Thus we have couple of questions:

  1. Whether Aspose supports localization of FormatTemplates in MhtMessageFormatter?
  2. Whether phrases in FormatTemplates depends on the windows locale or they are always in English?

Thanks in advance

Valeriy

Hi Liza,

Thank you for your inquiry.

We have looked into the API, it is not confirmed but it seems that FormatTemplates depend upon language setting of the local PC. It will not always be in English. You can use FormatTemplates property of MhtSaveOptions class to translate the formats. Sample code snippet is given below for your reference.

Sample Code:
string emlPath = "test_sample.eml";
MailMessage mail = MailMessage.Load(emlPath, new EmlLoadOptions());
MhtSaveOptions options = Aspose.Email.Mail.SaveOptions.DefaultMhtml;
options.MhtFormatOptions = MhtFormatOptions.WriteHeader;
options.FormatTemplates["From"] = options.FormatTemplates["From"].Replace("From:", "SOME_OTHER_WORD:");
options.FormatTemplates["Sent"] = options.FormatTemplates["Sent"].Replace("Sent:", "SOME_OTHER_WORD:");
options.FormatTemplates["To"] = options.FormatTemplates["From"].Replace("To:", "SOME_OTHER_WORD:");
options.FormatTemplates["Subject"] = options.FormatTemplates["Sent"].Replace("Subject:", "SOME_OTHER_WORD:");
mail.Save("test_sample_out.mhtml", options);

Furthermore it is suggested to use MthTemplateName instead of using phrases. For details please visit the API reference guide link MthTemplateName Class.

Please try it at your end and let us know your feedback. Keys that can be used for FormatTemplates are also given below:

  • PageHeader
  • Location
  • Start
  • End
  • ShowTimeAs
  • Recurrence
  • RecurrencePattern
  • Organizer
  • RequiredAttendees
  • DateTime
  • From
  • Sent
  • To
  • Cc
  • Bcc
  • Subject
  • Attachments


Hi Ikram,


Thank you for the quick answer.

My concern with suggested solution is that if the FormatTemplates do depend on the language setting of the PC, in this case the <span style=“background-color: rgb(255, 255, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Replace(“From:”, “SOME_OTHER_WORD:”) will not work as far as “From:” will be localized and contain other value.
Unfortunately we have English versions of Windows only and do not have any localized versions of Windows.

Do you have any possibility to check whether FormatTemplates will contain localized value for “From:” on the localized version of Windows or it still will be in English?

Thanks in advance

Hi,


Thank you for providing feedback.

We have tried this scenario by changing the system region and language and observed that same code works fine.

I am afraid that I do not have windows in a language, other than English, along with the setup to test this scenario. You may please use this code and write back to us if any problem is there.