Android NDK 是否支持语言环境? [英] Does the Android NDK support locales?

查看:90
本文介绍了Android NDK 是否支持语言环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真正想做的就是以正确的顺序使用 strftime(%x")格式化日期.在大多数平台上,只需调用 setlocale(").在Android设备上,我不断收到!@#$美国日期.

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.

那么,Android不支持语言环境吗?

So, does Android not support locales?

推荐答案

否. setlocale() strftime()在Android NDK中不起作用,除非您要使用en_US布局.

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

我通过以下方式从Java部分获得了本地语言:

I get the local language from the Java part by:

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

并且ANSI C localeconv()在Android NDK中不起作用:

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

struct lconv *localeconv(void);

此外,获取用户名的标准Unix方式在Android中也不起作用.

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

char *p = getenv("USER");

因此,您需要使用Java端来获取语言环境信息.

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);

这篇关于Android NDK 是否支持语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆