// Getter and Setter for locale
publicLocalegetLocale()publicvoidsetLocale(Localevalue)// Getter and Setter for localeBi
publicLocalegetLocaleBi()publicvoidsetLocaleBi(Localevalue)// Getter and Setter for localeFarEast
publicLocalegetLocaleFarEast()publicvoidsetLocaleFarEast(Localevalue)
In most cases, the output WordProcessing document generated from the EditableDocument instance by the Editor.save() method contains valid locales for the textual content. However, in some scenarios, it is necessary to explicitly set a specific locale for the output document. These three options provide that capability. Keep in mind that they are suitable only when the document should have a single locale. If the document is multilingual and contains, for example, English and Spanish text, setting the locale to English (“en-GB”) will mark the Spanish text as English too. As a result, spell checking in MS Word may not work properly for the Spanish text.
By default, all these three locale-related properties are not specified; their values are null. In such cases, MS Word (or other programs) will detect (or choose) the document locale according to their own settings or other factors. Additionally, if the document is multilingual, it is strongly recommended to enable the enableLanguageInformation property in the WordProcessingEditOptions class while editing the original document, and not to use these three properties.
The locale property is intended to set the locale for standard left-to-right text, which consists of letters.
The following example demonstrates how to set the locale properties when saving a WordProcessing document:
// Import necessary modules
constgroupdocs_editor=require('groupdocs-editor');constfs=require('fs');// Load the source WordProcessing document
consteditor=newgroupdocs_editor.Editor('SampleDoc.docx');// Create WordProcessingEditOptions and enable language information if needed
consteditOptions=newgroupdocs_editor.WordProcessingEditOptions();editOptions.enableLanguageInformation=true;// Edit the document to get an EditableDocument instance
consteditableDocument=editor.edit(editOptions);// Create WordProcessingSaveOptions
constsaveOptions=newgroupdocs_editor.WordProcessingSaveOptions();// Set the desired locale (e.g., English - United Kingdom)
saveOptions.locale=java.util.Locale.UK;// For right-to-left languages (e.g., Arabic - Saudi Arabia)
// saveOptions.localeBi = new java.util.Locale("ar", "SA");
// For Far East languages (e.g., Japanese)
// saveOptions.localeFarEast = java.util.Locale.JAPANESE;
// Save the edited document with the specified locale settings
editor.save(editableDocument,'OutputDoc.docx',saveOptions);console.log('Document saved successfully with specified locale.');
Note:
Replace 'SampleDoc.docx' with the path to your source document.
The java.util.Locale class is used to specify the locale. You can create a new locale by specifying the language and country codes.
Important Considerations
Single Locale Documents: These properties are suitable only when the document contains text in a single language. If your document is multilingual, using these properties might not yield the desired results.
Multilingual Documents: For documents containing multiple languages, it’s recommended to enable the enableLanguageInformation property in the WordProcessingEditOptions class and avoid setting the locale properties in WordProcessingSaveOptions.
Default Behavior: If the locale properties are not set, their values are null, and the locale will be determined by MS Word or other programs based on their settings.
Understanding the Locale Properties
locale: Sets the locale for standard left-to-right text, such as English, French, or German.
localeBi: Sets the locale for right-to-left (RTL) text, such as Arabic or Hebrew.
localeFarEast: Sets the locale for East Asian languages, including Chinese, Japanese, and Korean.
Specifying Locales
You can specify a locale using the java.util.Locale class. Here are some examples:
// English (United Kingdom)
saveOptions.locale=java.util.Locale.UK;// English (United States)
saveOptions.locale=java.util.Locale.US;// Spanish (Spain)
saveOptions.locale=newjava.util.Locale("es","ES");// Arabic (Saudi Arabia)
saveOptions.localeBi=newjava.util.Locale("ar","SA");// Chinese (Simplified)
saveOptions.localeFarEast=java.util.Locale.SIMPLIFIED_CHINESE;// Japanese
saveOptions.localeFarEast=java.util.Locale.JAPANESE;
Conclusion
By setting the locale properties in WordProcessingSaveOptions, you can control the language settings of your output WordProcessing documents when using GroupDocs.Editor for Node.js via Java. This is particularly useful when dealing with documents in specific languages or scripts, such as RTL or East Asian languages.