Setting the proofing language Word Document

Hello Aspose Team,

Whenever we have more than one language in configured in word document, it is showing track changes on every page of the modified word document. What I want, to force the word document to set the default language(US English) for our modified document.

Is there any way to achieve this requirement through Aspose Java word Api.? Can it be achieved this using proofing language?

@ketanpbh You can specify language using Font.LocaleId property.

You can also specify Styles.DefaultFont.LocaleId to set default language.

@alexey.noskov
Actually, I am using placeholder which will be replaced with the another document content when certain condition met. Problem with document content is some other language. Would you please provide one sample code.? If possible?

@ketanpbh You can also specify language preferences using LoadOptions.LanguagePreferences property while loading document:

LoadOptions opt = new LoadOptions();
opt.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.ENGLISH_US);
Document doc = new Document("C:\\Temp\\in.docx", opt);

If you would like to change language of existing content in the document, you can use code like this:

Document doc = new Document("C:\\Temp\\in.docx");

// Get runs and change locale
Iterable<Run> runs = (Iterable<Run>)doc.getChildNodes(NodeType.RUN, true);
// Change locale of all runs in the document.
for (Run r : runs)
    r.getFont().setLocaleId(1033);

doc.save("C:\\temp\\out.docx");

@alexey.noskov

Thanks you.
I have noticed that few places it does not set the ENGLISH_US.

Is it possible, with Aspose, to select all the content (like “Control+A”), and then to apply a Language?

@ketanpbh You can try using the following code to set locale of the whole document’s content:

Document doc = new Document("in.docx");
doc.accept(new FontLocaleChanger());
doc.save("out.docx");
public class FontLocaleChanger extends DocumentVisitor {

    /// <summary>
    /// Called when a FieldEnd node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldEnd(FieldEnd fieldEnd)
    {
        //Simply change font name
        resetFont(fieldEnd.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FieldSeparator node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldSeparator(FieldSeparator fieldSeparator)
    {
        resetFont(fieldSeparator.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FieldStart node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldStart(FieldStart fieldStart)
    {
        resetFont(fieldStart.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Footnote end is encountered in the document.
    /// </summary>
    @Override
    public int visitFootnoteEnd(Footnote footnote)
    {
        resetFont(footnote.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    @Override
    public int visitFormField(FormField formField)
    {
        resetFont(formField.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Paragraph end is encountered in the document.
    /// </summary>
    @Override
    public int visitParagraphEnd(Paragraph paragraph)
    {
        resetFont(paragraph.getParagraphBreakFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Run node is encountered in the document.
    /// </summary>
    @Override
    public int visitRun(Run run)
    {
        resetFont(run.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a SpecialChar is encountered in the document.
    /// </summary>
    @Override
    public int visitSpecialChar(SpecialChar specialChar)
    {
        resetFont(specialChar.getFont());
        return VisitorAction.CONTINUE;
    }

    private void resetFont(Font font)
    {
        if(mFontSize > 0)
            font.setLocaleId(1033);
    }
}

@alexey.noskov

Thank you! Alexey for your quick response.

I still facing the issue.

Is it possible to connect with you over zoom meeting?

Hello @alexey.noskov ,

I am sharing sample input file where I am running the above code.
Case -1
In the input file track change is enabled. When I have only one language in ms-word setting it looks good.

Input.docx (190.8 KB)

Case -2
What is problem?
When user has multiple language configured and Detect language automatically enable track changes are showing.

How to Reproduce the issue??
When we have more than one language is configured in ms-word (in my case I have configured French as a second language) and Detect Language Automatically enabled then track changes are showing in the documents.

Please refer the below snapshot for more details -

Steps to add second language in ms-word –

File Menu → Options → Language Tab → Add Additional Language.

Requirement - How to avoid track changes, when user has multiple language is configured & Detect language automatically enabled??

@ketanpbh

Unfortunately, we do not provide support via voice or video calls. The main place for getting support is this forum.

Unfortunately, I cannot reproduce the problem on my side. I have tested the scenario on my side with your and with synthetically created documents and on my side MS Word does not show revisions in the multilingual document when Detect Language Automatically enabled. The language remains the same as set in the code.

@alexey.noskov
What was the second language added by you?
Can I add French second language and try to reproduce the above issue?

@ketanpbh I have French language among the added languages: