Fix locale initialization in terminal (IDEA-171957)

This commit is contained in:
Dmitry Trofimov
2017-05-10 14:34:09 +02:00
parent d5b39cfcbf
commit 0afd759eb1
2 changed files with 14 additions and 8 deletions
@@ -315,17 +315,22 @@ public class EnvironmentUtil {
private static Map<String, String> setCharsetVar(@NotNull Map<String, String> env) {
if (!isCharsetVarDefined(env)) {
Locale locale = Locale.getDefault();
Charset charset = CharsetToolkit.getDefaultSystemCharset();
String language = locale.getLanguage();
String country = locale.getCountry();
String value = (language.isEmpty() || country.isEmpty() ? "en_US" : language + '_' + country) + '.' + charset.name();
env.put(LC_CTYPE, value);
String value = setLocaleEnv(env, CharsetToolkit.getDefaultSystemCharset());
LOG.info("LC_CTYPE=" + value);
}
return env;
}
@NotNull
public static String setLocaleEnv(@NotNull Map<String, String> env, @NotNull Charset charset) {
Locale locale = Locale.getDefault();
String language = locale.getLanguage();
String country = locale.getCountry();
String value = (language.isEmpty() || country.isEmpty() ? "en_US" : language + '_' + country) + '.' + charset.name();
env.put(LC_CTYPE, value);
return value;
}
private static boolean isCharsetVarDefined(@NotNull Map<String, String> env) {
return !env.isEmpty() && (env.containsKey(LANG) || env.containsKey(LC_ALL) || env.containsKey(LC_CTYPE));
}
@@ -17,7 +17,6 @@ package org.jetbrains.plugins.terminal;
import com.google.common.collect.Lists;
import com.intellij.execution.TaskExecutor;
import com.intellij.execution.configurations.EncodingEnvironmentUtil;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessHandler;
@@ -124,7 +123,9 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
envs.put("TERM", "xterm-256color");
}
EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(envs, myDefaultCharset);
if (SystemInfo.isMac) {
EnvironmentUtil.setLocaleEnv(envs, myDefaultCharset);
}
String[] command = getCommand(envs);