We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Default styles localization

Hi, short question:
Is there an option for the default docx-stylenames to be saved in another language (german in this case)?

Background:
We have been working with docx files saved with german locale settings for a long time.
For smooth aspose integration into our workflow I want to produce the german style names.
I have a simple map for stylename translation, but aspose saves them as new custom styles, so the document then contains 2 styles for every default word-style.
This leads to a problem when opening the file in Word, a “1” is appended to all these generated styles.

I am tempted to simply delete the default styles from the styles.xml, and make the aspose-generated styles the new defaults, but maybe there is a simpler solution (like just setting a locale for aspose).

Sample code i used (Java):

Map<Integer,String> deDe = new HashMap<Integer, String>();
deDe.put(StyleIdentifier.NORMAL, "Standard");

for(Style style : doc.getStyles()){
    if(style.getBuiltIn() && deDe.containsKey(style.getStyleIdentifier())){
        style.setName(deDe.get(style.getStyleIdentifier()));
    }
}

@sebastian.bulka,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your sample input Word document
  • Aspose.Words generated output DOCX file showing the undesired default style names
  • Aspose.Words for Java source code that you used on your end to generate above DOCX file.
  • Please attach your expected Word document showing only the German styles. You can create expected document by using Microsoft Word.

As soon as you get these pieces of information ready, we’ll start further investigation into your issue and provide you more information. Thanks for your cooperation.

Best regards,
Awais Hafeez

13707.word.zip (36.1 KB)
Hey @awais.hafeez,

I attach four documents for you.
The error is visible in the .aspose_saved_by_word file, where the ‘Standard’ styles gets a ‘1’ attached. (berschrift2 becomes berschrift21 too…)

.input is the (english) input file i used
.aspose is the file generated by my java code with aspose
.aspose_saved_by_word is the .aspose file, once opened and then saved by Word
.word is the file i actually would like to generate

all java Code i use (the Map needs to be extended for coverage of all styles, but it works as a MWE):

import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.Style;
import com.aspose.words.StyleIdentifier;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.io.FileInputStream;

import java.util.HashMap;
import java.util.Map;

public class AsposeTester {

    private static Map<Integer,String> deDe = new HashMap<Integer, String>();
    
    static{
        deDe.put(0, "Standard");
        deDe.put(1, "Überschrift 1");
        deDe.put(2, "Überschrift 2");
    }
    
    /**
     * Translate all Builtin Styles to given language.
     * @param doc Document to be modified
     * @param language identifying language base on tags stated here: https://msdn.microsoft.com/en-us/library/cc233982.aspx
     */
    public static void translateBuiltinStyles(Document doc, String language){
        switch(language){
            case "en-EN": case "en-US":
                break;
            case "de-DE":
                for(Style style : doc.getStyles()){
                    System.out.println("oldName: "
                            + style.getName() +", "+style.getStyleIdentifier());
                    if(style.getBuiltIn() && deDe.containsKey(style.getStyleIdentifier())){
                        style.setName(deDe.get(style.getStyleIdentifier()));
                        System.out.println("newName: "
                                + style.getName());
                    }
                }
                break;
            default: break;
        }
    }
    
    public static void main(String[] args) throws Exception {
        License lic = new License();
        lic.setLicense(new FileInputStream("/home/sbulka/dev/aspose/license/Aspose.Words.lic"));
        System.out.println("licensed:" + lic.isLicensed());
        // The path to the documents directory.
        String dataDir = "/home/sbulka/sandbox/13707.word/";
        String fileName = "styles_test.input.docx";
        // Load the document from disk.
        Document doc = new Document(dataDir + fileName);
    
        translateBuiltinStyles(doc, "de-DE");

        // Save the finished document to disk.
        doc.save(dataDir + fileName + ".aspose.docx");
        
        System.out.println("Document loaded and saved successfully.");
    }
}

Thank you for your fast response,
Sebastian

@sebastian.bulka,

Thanks for your inquiry. We have logged your requirement in our issue tracking system. Your ticket ID is WORDSNET-15562 Our product team will further look into the details of this problem and we will keep you updated on the status of this issue. We apologize for any inconvenience.

Best regards,
Awais Hafeez

@sebastian.bulka,

We are currently working on your issue (WORDSNET-15562). But, we request you to please elaborate your inquiry further by providing complete details of your use-case. What do you want to achieve exactly? Thanks for being patient and your cooperation.

@sebastian.bulka,

We are waiting for your further input on this topic. Please see my previous post and share your further thoughts. Thanks for your cooperation.