3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

Always use UTF-8 for loading translations

(cherry picked from commit 624b3a449b5746cee84557992b9b217ac135cf50)
Dieser Commit ist enthalten in:
Octavia Togami 2020-01-29 04:31:09 -08:00 committet von MattBDev
Ursprung f4d03291c5
Commit d5828861de

Datei anzeigen

@ -33,7 +33,9 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Locale;
@ -85,15 +87,17 @@ public class TranslationManager {
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}
private Map<String, String> parseTranslationFile(InputStream inputStream) {
return filterTranslations(gson.fromJson(new InputStreamReader(inputStream), STRING_MAP_TYPE));
private Map<String, String> parseTranslationFile(InputStream inputStream) throws IOException {
try (Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
return filterTranslations(gson.fromJson(reader, STRING_MAP_TYPE));
}
}
private Optional<Map<String, String>> loadTranslationFile(String filename) {
Map<String, String> baseTranslations;
try {
baseTranslations = parseTranslationFile(ResourceLoader.getResourceRoot("lang/" + filename).openStream());
try (InputStream stream = ResourceLoader.getResourceRoot("lang/" + filename).openStream()) {
baseTranslations = parseTranslationFile(stream);
} catch (IOException e) {
// Seem to be missing base. If the user has provided a file use that.
baseTranslations = new ConcurrentHashMap<>();
@ -101,8 +105,8 @@ public class TranslationManager {
File localFile = worldEdit.getWorkingDirectoryFile("lang/" + filename);
if (localFile.exists()) {
try {
baseTranslations.putAll(parseTranslationFile(new FileInputStream(localFile)));
try (InputStream stream = new FileInputStream(localFile)) {
baseTranslations.putAll(parseTranslationFile(stream));
} catch (IOException e) {
// Failed to parse custom language file. Worth printing.
e.printStackTrace();