Skip to content Skip to sidebar Skip to footer

Does The Android Ndk Support Locales?

All I really want to do is format a date using strftime('%x') in the right order. On most platforms a call to setlocale('') is enough. On Android I keep getting !@#$ US dates. So,

Solution 1:

No. setlocale() and strftime() does not work in Android NDK, except if en_US layout is what you want.

I get the local language from the Java part by:

pLocaleData->pLocaleLanguage = new Locale("en").getDefault().getLanguage();

And the ANSI C localeconv() does not work in Android NDK:

structlconv *localeconv(void);

Also the standard Unix way of getting user name, does not work in Android.

char *p = getenv("USER");

So you need to use the Java side to get the locale information.

StringLocaleCountry=newLocale("en").getDefault().getCountry();
StringLocaleLanguage=newLocale("en").getDefault().getLanguage();
StringLocaleCurrency=newDecimalFormatSymbols().getCurrency().toString();
StringLocaleShortDateTimePattern=newSimpleDateFormat().toPattern();
charLocaleDecimalSeparator=newDecimalFormatSymbols().getDecimalSeparator();
charLocaleThousandSeparator=newDecimalFormatSymbols().getGroupingSeparator();
StringLocaleThousandGrouping= 
        String.format("%d;0", newDecimalFormat().getMaximumFractionDigits());
StringLocaleNegativePrefix=newDecimalFormat().getNegativePrefix();
StringLocaleNegativeSuffix=newDecimalFormat().getNegativeSuffix();
StringOperator= Utils.getQwnername(context);

Solution 2:

According to this the answer is No.

There is no support for locales in the C library / from native code, and this is intentional. As Elliot pointed out, your only hope is to use JNI to get relevant values.

Post a Comment for "Does The Android Ndk Support Locales?"