Number shaping for Bengali and Marathi in ibm icu library

Viewed 95

I wanted to know why the numbers are shaping (not displayed in Latin format) for Bengali and Marathi only as I tried for various other languages using ibm.icu library, refer below code and its result -

Code -

import com.ibm.icu.text.DateFormat;

import java.util.Date;
import java.util.Locale;

public static void main() {

        final Locale english = new Locale("en", "IN");
        final Locale hindi = new Locale("hi", "IN");
        final Locale tamil = new Locale("ta", "IN");
        final Locale telugu = new Locale("te", "IN");
        final Locale kannada = new Locale("kn", "IN");
        final Locale malayalam = new Locale("ml", "IN");
        final Locale marathi = new Locale("mr", "IN");
        final Locale bengali = new Locale("bn", "IN");
        final Locale gujrati = new Locale("gu", "IN");

        Locale[] availableLocales = new Locale[]{english, hindi, tamil, telugu, kannada, malayalam, marathi, bengali, gujrati};

        for (Locale availableLocale : availableLocales) {
            System.out.println(availableLocale.getDisplayLanguage());
            printer(availableLocale);
            System.out.println("--------");
        }
    }


    private static void printer(final Locale locale) {
        DateFormat df = DateFormat.getInstanceForSkeleton("EEEE, MMMM d, YYYY", locale);
        System.out.println(df.format(new Date()));
    }

Result -

English
Friday 19 March 2021
--------
Hindi
शुक्रवार, 19 मार्च 2021
--------
Tamil
வெள்ளி, 19 மார்ச், 2021
--------
Telugu
19, మార్చి 2021, శుక్రవారం
--------
Kannada
ಶುಕ್ರವಾರ, ಮಾರ್ಚ್ 19, 2021
--------
Malayalam
2021, മാർച്ച് 19, വെള്ളിയാഴ്‌ച
--------
Marathi
शुक्रवार, १९ मार्च, २०२१
--------
Bengali
শুক্রবার, ১৯ মার্চ, ২০২১
--------
Gujarati
શુક્રવાર, 19 માર્ચ, 2021

Use case -

  • I want numbers to be displayed in Latin format only for all languages.

Query -

  • How this can be fixed?
  • Why numbers are not formatted in latin format for these locales?
1 Answers

You can force Latin digits by creating your Locales with the standard Unicode extension nu, whose standard values include latn. I don’t know if it works in the ibm.icu library, but I know that this works with java.text.SimpleDateFormat:

final Locale english = Locale.forLanguageTag("en-IN-u-nu-latn");
final Locale hindi = Locale.forLanguageTag("hi-IN-u-nu-latn");
final Locale tamil = Locale.forLanguageTag("ta-IN-u-nu-latn");
final Locale telugu = Locale.forLanguageTag("te-IN-u-nu-latn");
final Locale kannada = Locale.forLanguageTag("kn-IN-u-nu-latn");
final Locale malayalam = Locale.forLanguageTag("ml-IN-u-nu-latn");
final Locale marathi = Locale.forLanguageTag("mr-IN-u-nu-latn");
final Locale bengali = Locale.forLanguageTag("bn-IN-u-nu-latn");
final Locale gujrati = Locale.forLanguageTag("gu-IN-u-nu-latn");
Related