【Java】【45】获取系统的语言环境

前言:

比如一个官网,有三种语言版本,需要根据用户的语言环境,优先显示对应的语言页面

正文:

String language = HttpHelper.getRequest().getLocale().getLanguage();
String country = HttpHelper.getRequest().getLocale().getCountry();

//大陆是简写,香港台湾是繁体,所以还得再用country字段判断下
if(("zh").equals(langType) && ("CN").equals(country)){            
  language = "sc"; //简体中文            
}

语言缩写:

English:en ;Chinese:zh;

国家及地区缩写:

中国:CN;台湾省:TW;香港特别行政区:HK;

参考博客:

各国语言缩写

http://www.loc.gov/standards/iso639-2/php/code_list.php

国家和地区简写

https://blog.csdn.net/wjw_java_android/article/details/20458507

猜你喜欢

转载自www.cnblogs.com/huashengweilong/p/11349139.html