2017年6月28日星期三

国际化语言设置


在下面中 local是国家代码, region是地区代码. region可有可无.比如汉语的话可能有繁体,跟简体.这种时候就需要region的代码了.在国际化语言设置的时候 这个可以根据 values当中的国际化语言参考设置.比如 values-ex-rMX. 这个是 西班牙的墨西哥语言. 所以 local就成了 es(西班牙), region成为了
mx(南美语).

        Locale locale = new Locale(local, region);
            Configuration config = new Configuration();            config.locale = locale;            App.getAppContext().getResources().updateConfiguration(config, App.getAppContext().getResources().getDisplayMetrics());


除了这个再看看 java中日期的国际化设置.
也是很简单.都是使用 Locale的.
但需要注意的是 比如你想对 月进行国际化翻译的话 'MMM'.一般是2个M,但如果是3个M的话
他就会翻译成国际化的语言.比如JUN

Locale locale = new Locale(language, countryCode);

SimpleDateFormat fromFormat = new SimpleDateFormat("yyyyMMdd");SimpleDateFormat newFormat  = new SimpleDateFormat("yyyyMMMdd", locale);
Date startDate = null;try{    startDate = fromFormat.parse("20170604");}catch(ParseException e){    e.printStackTrace();}return newFormat.format(startDate);