Aspose Locale issues

Hello,
Lately, we are running into a particular locale related issues, i.e Aspose.Words is unable to format the numbers into the correct locale. We figured out a fix, but I’m wondering if there is a list of locales that Aspose supports or doesn’t support.

Thank you!
Brunda

@gbrunda

Hello Brunda,

Thank you for reaching out and sharing your locale-related issue with Aspose.Words. We appreciate your detailed feedback.

Would you please provide an example of the locale you’re experiencing issues with? The more specific you can be, the better we can assist you with a solution.

Here’s how you can set the culture:

Document doc = new Document();
doc.Styles.DefaultParagraphFormat.ParagraphFormat.LocaleId = 1033; // English (United States)

Please refer to Aspose documentation for LocaleId property:
LocaleId Property

Looking forward to your response.

Best regards,
[Your Name]
Aspose Support Team

Hello,

The current locale we are running into an issue is en_DE. de_DE works with our fix.

@gbrunda Aspose.Words by default uses locale specified in the current thread to format values in fields. Locale using code like this:

Locale current = CurrentThreadSettings.getLocale();
CurrentThreadSettings.setLocale(Locale.forLanguageTag("en-US"));

// your code here

CurrentThreadSettings.setLocale(current);

@alexey.noskov - Does that mean if we set the correct Locale, in the current thread it should work?

@rootforms - FYI

@alexey.noskov - We do set the Locale on the CurrentThread but still have issues with en_DE

@gbrunda Please try using en-DE instead of en_DE.

@alexey.noskov , the result is still the same.

  • We set en-DE in CurrentThreadSettings.setLocale(Locale.forLanguageTag(“en-DE”));
  • cross checking locale with CurrentThreadSettings.getLocale(). We see en_DE.
  • Execute the program. The number output still shows the delimiter as ‘.’, and not the ‘,’…which is expected for Germany.

@rootforms Could you please attach your input and output documents along with simple code and data that will allow us to reproduce the problem? We will check the scenario on our side and provide you more information.

AsposeTest.zip (123.4 KB)

@alexey.noskov , this attachment has input, output, template files and class file.

@rootforms Thank you for additional information. But as I can see the attached de-DE-localeBasedOutput.pdf and en-DE-localeBasedOutput.pdf are exactly the same. Could you please check?

Yes @alexey.noskov , thats correct. However, the number values rendered under Unit Price/ Amount are not correctly formatted for DE based locales.

This discussion about issue with DE locales dates back to the last discussion thread with my colleague, Amit : Number format not applied on merged field.
Post that discussion, per your advice, we implemented IFieldMergingCallback. And our locale based usecases that time worked well for us. With iFieldMergingCallback, even de_DE works as expected. However, en_DE isn’t.

Here is the callback implementation for your reference.
CustomFieldMergingCallback.zip (895 Bytes)

This was the background for opening this discussion with Aspose support, to get the list of locales, which needs custom handling to deal with them. Thanks!

@rootforms If you use FieldMergingArgs.setText method, the provided text is set as field value. Aspose.Words does not format the value in this case. In your implementation of IFieldMergingCallback the value is formatted by DecimalFormat instance, that is not part of Aspose.Words. Most likely, DecimalFormat is not properly returned for en_DE culture, but this problem is not related to Aspose.Wrods.

True @alexey.noskov, the custom code working isn’t related to Aspose.words. We are working separately for that particular locale in our custom code.
BTW, we need custom code because, for our use case, the formatted values are not rendered appropriately if we use Aspose.words API.

From this discussion thread, we are seeking a list of such locales which Aspose is aware of, which needs custom handling to work appropriately. Otherwise we may have to wait for our customers to report, which can be avoided.

@gbrunda Do you mean the following list?
CultureInfo.zip (45.6 KB)

This list can be fond in Aspose.Words JAR com/aspose/words/resources/CultureInfo.xml

@alexey.noskov—Kind of. This only provides the Date/Time formats, not the number formats. Is there a different file for that?

As a follow-up, if the locale is not present in the culture file, does that mean Aspose will not be able to format it correctly? And can we add any entries to this file?

@gbrunda No, there is no another file for number format. Aspose.Words uses standard Java DecimalFormat to format numeric values. If Aspose.Words does not format value correctly, this is a a bug.

No, you cannot add entries to this file.