如何在 Windows 上永久更改 java 的默认语言环境

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1109438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:13:09  来源:igfitidea点击:

How do I permanently change java's default locale on Windows

javalocaleapplication-server

提问by Manos Dilaverakis

I need to change the default locale that java uses on a Windows 2008 Server machine. Java is installed as part of an Oracle + Application server setup. I can do this in code, but I need to permanently change this setting.

我需要更改 java 在 Windows 2008 Server 机器上使用的默认语言环境。Java 作为 Oracle + 应用程序服务器设置的一部分进行安装。我可以在代码中执行此操作,但我需要永久更改此设置。

Edit: I should note that we're talking about jsp pages served via Application server so I can't exactly pass command line arguments to java. Also the machine's regional and language options are already set to what I need (Greek). Java's default locale is still en_US instead of el_GR.

编辑:我应该注意到我们正在谈论通过应用程序服务器提供的 jsp 页面,所以我不能完全将命令行参数传递给 java。此外,机器的区域和语言选项已经设置为我需要的(希腊语)。Java 的默认语言环境仍然是 en_US 而不是 el_GR。

Edit and solution: I was porting an existing app to a new server. The app took the default locale for granted, which didn't work out so well on the new server (it-works-on-my-machine in all its glory). I was hoping of not having to touch the code itself, but finally decided to explicitly set the default locale in-code in a file that's already included by all the pages. Not the most elegant of solutions, but wth, it works.

编辑和解决方案:我正在将现有应用程序移植到新服务器。该应用程序将默认语言环境视为理所当然,这在新服务器上效果不佳(它在我的机器上运行良好)。我希望不必接触代码本身,但最终决定在所有页面都已包含的文件中显式设置代码中的默认语言环境。不是最优雅的解决方案,但它确实有效。

回答by Nate

Would specifying the locale on the command like that starts the JVM work?

在命令上指定语言环境会启动 JVM 工作吗?

java -Duser.language=2-char-language-code -Duser.region=2-char-country-code

java -Duser.language=2-char-language-code -Duser.region=2-char-country-code

http://www.oracle.com/technetwork/articles/javase/locale-140624.html

http://www.oracle.com/technetwork/articles/javase/locale-140624.html

回答by Martin Bartlett

In fact there are two answers I found - the WRONG one presented by http://java.com/en/download/help/locale.xmland the hack one that works.

事实上,我找到了两个答案 - http://java.com/en/download/help/locale.xml提出的错误答案和有效的 hack答案。

I'll explain - I use a French-installed multi-language XP in France with a French keyboard - but I want my apps to speak to me in English. The page at Sun plain does not work with that combination - Java still talks to me in French.

我会解释一下 - 我在法国使用安装了法语的多语言 XP 和法语键盘 - 但我希望我的应用程序用英语跟我说话。Sun plain 的页面不适用于这种组合——Java 仍然用法语与我交谈。

The HACK solution was to go into regedit and change HKEY_CURRENT_USER\Control Panel\International\Locale from 0000040C to 00000409. That made Java talk English.

HACK 解决方案是进入 regedit 并将 HKEY_CURRENT_USER\Control Panel\International\Locale 从 0000040C 更改为 00000409。这使 Java 说英语。

Going back to the regional settings control panel tool, I noticed that this, in fact, had changed the name in the "Regional Options" drop down, while keeping all the French formatting for numbers dates etc.

回到区域设置控制面板工具,我注意到这实际上已经更改了“区域选项”下拉菜单中的名称,同时保留了数字日期等的所有法语格式。

So that page at Sun is plain wrong!! Java does NOT get its default LOCALE from the settings on the advanced page, but from the settings on the Regional Options page - and THEY are very tough to change without screwing up ALL those options (i.e. you can't easily just change the language and leave the number/date/etc formatting as is).

所以 Sun 上的那一页是完全错误的!!Java 不会从高级页面上的设置中获取其默认 LOCALE,而是从“区域选项”页面上的设置中获取 - 而且它们很难在不搞砸所有这些选项的情况下进行更改(即,您不能轻易地更改语言和保持数字/日期/等格式不变)。

Anyone know how to get that information to Sun???

任何人都知道如何将这些信息提供给Sun???

回答by orbanbalage

For me changing the HKEY_CURRENT_USER\Control Panel\International\LocaleNameto en-USdid the trick. Changing the Locale as Martin Bartlett suggested didn't help.

对我来说,改变HKEY_CURRENT_USER\Control Panel\International\LocaleNametoen-US成功了。按照 Martin Bartlett 的建议更改语言环境并没有帮助。

回答by hao

  1. user.language and user.country work, you can try the following examples:
  1. user.language 和 user.country 工作,你可以试试下面的例子:
    java -Duser.language=sv -Duser.country=SE
    java -Duser.language=en -Duser.country=US

  1. If you want jvm to select it by default, you should set environment variable JAVA_TOOL_OPTIONS, it works on windows too (except that setting environment variable is a little different on windows)!
  1. 如果你想让jvm默认选择它,你应该设置环境变量JAVA_TOOL_OPTIONS它也适用于windows(除了windows设置环境变量有点不同)
    export JAVA_TOOL_OPTIONS="-Duser.language=en -Duser.country=US"

Please refer to this question for details of JAVA_TOOL_OPTIONS.

有关 JAVA_TOOL_OPTIONS 的详细信息,请参阅此问题