Font.LocaleID

Hi,

I need to change the spell-checking language for an entire document (that is created dynamically). Is this possible in a general manner like

Aspose.Word.Document doc = new Aspose.Word.Document();

// pseudo-code below - I know it doesn't work....
doc.Font.LocaleId = xx;

- or do I have to set the localeId on each and every style change after I call builder.Font.ClearFormatting() ?

// reset to default values
builder.Font.ClearFormatting();
builder.Font.Size = 10;
builder.Font.LocaleId = xx;

Second; the documentatation states nothing about the value of the LocaleId property. It's just an integer. Where do I find information on WHICH integer to use for which language? Right now I want to be able to switch between danish and english.

Thanks in advance !

List of supported locale identifiers for MS Word can be found here:

http://support.microsoft.com/?kbid=221435

For example, Danish is 1030 (&H406), English U.S. is 1033 (&H409) .

To change LocaleId for the entire document you need to execute the following code:

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach(Paragraph paragraph in paragraphs) {

paragraph.Font.LocaleId = 1030;

}

NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);

foreach(Run run in runs) {

paragraph.Font.LocaleId = 1030;

}

Hi,

Thanks for the answer. However, it doesn't seem to work. I discovered the 1030-value by creating a word document with danish text and opening it with aspose.word. Then I created a document like this (which now includes your suggestion):

Aspose.Word.Document doc2 = new Aspose.Word.Document();

Aspose.Word.DocumentBuilder builder = new Aspose.Word.DocumentBuilder(doc2);

builder.PageSetup.PaperSize = Aspose.Word.PaperSize.A4;

builder.PageSetup.RightMargin = cmToPoints(2);

builder.PageSetup.LeftMargin = cmToPoints(2);

builder.PageSetup.TopMargin = cmToPoints(3);

builder.PageSetup.BottomMargin= cmToPoints(3);

builder.Font.LocaleId = 1030;

builder.Font.Bold = true;

builder.Write("dette skulle være dansk");

builder.Font.LocaleId = 1030;

NodeCollection paragraphs = doc2.GetChildNodes(NodeType.Paragraph, true);

foreach(Paragraph paragraph in paragraphs)

{

paragraph.Font.LocaleId = 1030;

}

doc2.Save(

System.IO.Path.Combine(System.Environment.CurrentDirectory, "generated.doc"),

Aspose.Word.SaveFormat.FormatDocument);

- but the output is still reported as "English (U.S.)". Re-opening it with aspose reveals that the locationId is 1030, but Word doesn't recognize it.

I've attached a zip with my test-app so you can try it out. in .\bin\debug\ you'll find "danish.doc" that is all danish and the application has three buttons:

1) read and report all locationId's within "danish.doc"

2) create a document with only danish (1030) text, as illustrated in the code above.

3) read and report all locationId's within "generated.doc"

Button 1 reports "1030" to me.

Button 2 creates file that - when opened in word - contains only english (US) text

Button 3 reports that the "generated.doc" file is written with locationId 1030.

I don't get it. I set the value - I can read the value again - but word doesn't recognize it.

I'm using Microsoft Office 2002 (XP).

BTW: will iterating over paragraph nodes of a document also set the locationId of text within table cells ?

It is more important to iterate through runs, than paragraphs:

NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);

foreach (Run run in runs) {

run.Font.LocaleId = 1030;

}

because setting

paragraph.Font.LocaleId = 1030;

influences only autonumbering in lists.

Nevertheless, it still does not influence the language setting, which is seeing in MS Word. Right now I cannot offer you any way of doing this.

I have added it to our defect list, so we will deal with this issue as soon as our schedule permits.

OK - thanks for the answer. I’ll be looking forward to the day when it works.

This is fixed in Aspose.Words 3.5.1 that will be released in a few days.

This code works to set language of the text you are inserting into a document:

DocumentBuilder b = new DocumentBuilder();
b.Font.LocaleId = 1030;
b.Writeln("Hello");
TestUtil.Save(b.Document, @"Model\Run\TestLocaleId Out.doc");

You can also excercise other means described in the above examples as well as setting the language on the style (which is probably the easiest if most cases):

Document doc = new Document();
doc.Styles["Normal"].Font.LocaleId = 1030;