在 Java Web 应用程序中获取当前语言环境
在 java web 应用程序中,区域设置信息是从服务器端获取的 ServletRequest(和 HttpServletRequest)对象中检索的。
Locale currentLocale = httpServletRequest.getLocale(); System.out.println(currentLocale.getDisplayLanguage()); System.out.println(currentLocale.getDisplayCountry()); System.out.println(currentLocale.getLanguage()); System.out.println(currentLocale.getCountry()); //Output: English United States en US
https://onitroad.com 更多教程
在 Java 桌面应用程序中获取当前语言环境
在 Java 桌面应用程序中,区域设置信息是使用 Locale.getDefault();方法调用来检索的。
我们还可以使用系统属性“user.country”和“user.language”来获取此信息。
Locale currentLocale = Locale.getDefault();
System.out.println(currentLocale.getDisplayLanguage());
System.out.println(currentLocale.getDisplayCountry());
System.out.println(currentLocale.getLanguage());
System.out.println(currentLocale.getCountry());
System.out.println(System.getProperty("user.country"));
System.out.println(System.getProperty("user.language"));
Output:
English
United States
en
US
US
en
日期:2020-09-17 00:09:20 来源:oir作者:oir
