Default language for document

Dear Sir or Madam,

We use aspose.words on two different servers (production and testing). The word outputs of production have language set to Australian while Test produces the documents with language set to US. Is there a way to set global document language or maybe you could suggest what can affect Aspose.Words in terms of producing different outputs on different servers?

Regards,
Alex

@AlexanderNovickov,

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:

    LoadOptions loadOptions = new LoadOptions();
    loadOptions.LanguagePreferences.AddEditingLanguage(EditingLanguage.Japanese);
     
    Document doc = TestUtil.Open(@"in.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 Awaiz,

thank you for a prompt reply. Is there any way to apply settings to a newly created document?
mOutputDocument = new AW.Document();
We build the document from scratch on server into a stream and then server sends it to a user.

I tried this workaround:

        using (MemoryStream ms = new MemoryStream())
        {
            mOutputDocument.Save(ms, SaveFormat.Docx);
            ms.Position = 0;
            LoadOptions loadOptions = new LoadOptions();
            loadOptions.LanguagePreferences.SetAsDefault(EditingLanguage.EnglishAustralia);
            mOutputDocument = new AW.Document(ms, loadOptions);
        }
        return mOutputDocument;

but it didn’t work for me. I have uploaded both document and screenshot showing the issue.
Alex test-Annual Report-Alex test-TestNewTable.zip (117.3 KB)

Regards,
Alex

@AlexanderNovickov,

Please check if the following code resolves this issue on your end?

Document doc = new Document("D:\\Temp\\Alex test-Annual Report-Alex test-TestNewTable (2).docx");

foreach(Run run in doc.GetChildNodes(NodeType.Run, true))
{
    run.Font.LocaleId = 3081; // LCID 3081 for English (Australia) Locale
}

doc.Save("D:\\Temp\\18.7.docx");

Output produced on our end is attached (see 18.7.zip (82.9 KB)).

Hi Awaiz,

Thank you, it works.

But I still have a question. I was able to figure out the difference between the servers. One uses 17.8.0.0 and produces output as Australian, another one uses 18.6.0.0 and produces US. Looks like some settings were changed between these two releases and I wonder if it is possible to set these settings on users side? The workaround with enumerating the Runs works as I mentioned but for me it looks like a workaround rather than a solution.

Regards,
Alex

@AlexanderNovickov,

Thanks for the additional information. We have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-17178. We will further look into the details of this problem and will keep you updated on the status of this issue. We apologize for your inconvenience.

@AlexanderNovickov,

Please also check the values of “System.Text.Encoding.Default.CodePage” on both servers. Are they same? This may be the reason of different behavior.

Console.WriteLine(System.Text.Encoding.Default.CodePage);

Hi Awais,

I was able to reproduce it on my local computer. Of course CodePage was the same in both cases.

Alex

@AlexanderNovickov,

Thanks for the additional information. We will keep you posted on further updates.

@AlexanderNovickov,

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

Document doc = new Document("D:\\Temp\\Alex test-Annual Report-Alex test-TestNewTable (2).docx");
// doc.Styles.DefaultFont.LocaleId = 3081;
doc.Styles.DefaultFont.LocaleId = (int)EditingLanguage.EnglishAustralia;
doc.Save("D:\\Temp\\18.8.docx");

If not, please also provide documents from your both servers to investigate the issue further.

@AlexanderNovickov,

We are waiting for your further input on this topic. Please see my previous post and share documents from your both servers (machines) to investigate the issue further. Thanks for your cooperation.

Hi Awais, sorry for delay. Yes the workaround is acceptable.

Regards,
Alex