Does the Android NDK support locales?

拥有回忆 提交于 2021-01-28 05:09:39

问题


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, does Android not support locales?


回答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:

struct lconv *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.

String LocaleCountry = new Locale("en").getDefault().getCountry();
String LocaleLanguage = new Locale("en").getDefault().getLanguage();
String LocaleCurrency = new DecimalFormatSymbols().getCurrency().toString();
String LocaleShortDateTimePattern =new SimpleDateFormat().toPattern();
char LocaleDecimalSeparator = new DecimalFormatSymbols().getDecimalSeparator();
char LocaleThousandSeparator = new DecimalFormatSymbols().getGroupingSeparator();
String LocaleThousandGrouping = 
        String.format("%d;0", new DecimalFormat().getMaximumFractionDigits());
String LocaleNegativePrefix = new DecimalFormat().getNegativePrefix();
String LocaleNegativeSuffix =new DecimalFormat().getNegativeSuffix();
String Operator = Utils.getQwnername(context);



回答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.



来源:https://stackoverflow.com/questions/23427230/does-the-android-ndk-support-locales

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!