如何在 JVM 中设置默认语言环境? [英] How do I set the default locale in the JVM?

查看:28
本文介绍了如何在 JVM 中设置默认语言环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的 JVM 的默认 Locale 设置为 fr_CA.执行此操作的可能选项是什么?

I want to set the default Locale for my JVM to fr_CA. What are the possible options to do this?

我只知道一个选项 Locale.setDefault()

推荐答案

来自 Oracle参考:

应用程序的默认语言环境由三种方式确定.首先,除非您明确更改了默认值,否则Locale.getDefault() 方法返回最初确定的语言环境首次加载时由 Java 虚拟机 (JVM) 执行.那就是JVM 根据主机环境确定默认语言环境.主人环境的区域设置由主机操作系统和在该系统上建立的用户偏好.

The default locale of your application is determined in three ways. First, unless you have explicitly changed the default, the Locale.getDefault() method returns the locale that was initially determined by the Java Virtual Machine (JVM) when it first loaded. That is, the JVM determines the default locale from the host environment. The host environment's locale is determined by the host operating system and the user preferences established on that system.

其次,在某些 Java 运行时实现上,应用程序用户可以通过提供以下信息来覆盖主机的默认语言环境通过设置 user.languageuser.countryuser.variant 系统属性.

Second, on some Java runtime implementations, the application user can override the host's default locale by providing this information on the command line by setting the user.language, user.country, and user.variant system properties.

第三,您的应用程序可以调用Locale.setDefault(Locale)方法.setDefault(Locale aLocale) 方法让您的应用程序设置系统范围的(实际上是虚拟机范围的) 资源.使用此设置默认语言环境后方法,随后对 Locale.getDefault() 的调用将返回新的设置语言环境.

Third, your application can call the Locale.setDefault(Locale) method. The setDefault(Locale aLocale) method lets your application set a systemwide (actually VM-wide) resource. After you set the default locale with this method, subsequent calls to Locale.getDefault() will return the newly set locale.

这篇关于如何在 JVM 中设置默认语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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