Set the language for an entire Word document

Hello,

I know I can set the language of text using the LocaleId property of Font, but how can I set the language of an entire Word document like you can in Microsoft Word?

Thanks,

Paul

@brinkp,

You can get or set default editing language by using the LanguagePreferences.DefaultEditingLanguage Property. Sample code is as follows:

Add Japanese language to the editing languages:

Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LanguagePreferences.AddEditingLanguage(EditingLanguage.Japanese);

Document doc = new Document("D:\\Temp\\input.docx", loadOptions);

int localeIdFarEast = doc.Styles.DefaultFont.LocaleIdFarEast;
if (localeIdFarEast == (int)EditingLanguage.Japanese)
    Console.WriteLine("The document either has no any FarEast language set in defaults or it was set to Japanese originally.");
else
    Console.WriteLine("The document default FarEast language was set to another than Japanese language originally, so it is not overridden.");

You may also check other properties/methods of LanguagePreferences Class.

Hi awais.hafeez,

Thank you very much for your help, much appreciated!

Your example works fine when loading an existing document from file. Is it also possible to do this with a new document? For example something like:

Document document = new Document();

document.LanguagePreferences.AddEditingLanguage(EditingLanguage. Japanese);

Thanks a lot in advance,
Paul

@brinkp,

It should also work. In case you still face any problem, please share complete simplified code here for testing.

I’m afraid I did not make myself clear: the examples I gave are what I would like to have, they are currently not possible…

  • There is no constructor for Document (without a stream or filename parameter) with a LoadOptions parameter.

  • There is also no LanguagePreferences or likewise property for Document.

So I am looking for another way of achieving this.

@brinkp,

Please check the following code if that is acceptable for you?

Document doc = new Document();
doc.Styles.DefaultFont.LocaleId = (int)EditingLanguage.Japanese;
doc.Save("D:\\Temp\\18.8.docx");

Also, please check the following code:

Document doc = new Document();
MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Docx);

Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LanguagePreferences.AddEditingLanguage(EditingLanguage.Japanese);

Document docx = new Document(stream, loadOptions);
docx.Save("D:\\temp\\18.8.docx");

Thanks for your help, awais.hafeez: this did the trick!
Paul