Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 11:00:04 +01:00
Always use UTF-8 for loading translations
(cherry picked from commit 624b3a449b5746cee84557992b9b217ac135cf50)
Dieser Commit ist enthalten in:
Ursprung
f4d03291c5
Commit
d5828861de
@ -33,7 +33,9 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -85,15 +87,17 @@ public class TranslationManager {
|
|||||||
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
|
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> parseTranslationFile(InputStream inputStream) {
|
private Map<String, String> parseTranslationFile(InputStream inputStream) throws IOException {
|
||||||
return filterTranslations(gson.fromJson(new InputStreamReader(inputStream), STRING_MAP_TYPE));
|
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) {
|
private Optional<Map<String, String>> loadTranslationFile(String filename) {
|
||||||
Map<String, String> baseTranslations;
|
Map<String, String> baseTranslations;
|
||||||
|
|
||||||
try {
|
try (InputStream stream = ResourceLoader.getResourceRoot("lang/" + filename).openStream()) {
|
||||||
baseTranslations = parseTranslationFile(ResourceLoader.getResourceRoot("lang/" + filename).openStream());
|
baseTranslations = parseTranslationFile(stream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Seem to be missing base. If the user has provided a file use that.
|
// Seem to be missing base. If the user has provided a file use that.
|
||||||
baseTranslations = new ConcurrentHashMap<>();
|
baseTranslations = new ConcurrentHashMap<>();
|
||||||
@ -101,8 +105,8 @@ public class TranslationManager {
|
|||||||
|
|
||||||
File localFile = worldEdit.getWorkingDirectoryFile("lang/" + filename);
|
File localFile = worldEdit.getWorkingDirectoryFile("lang/" + filename);
|
||||||
if (localFile.exists()) {
|
if (localFile.exists()) {
|
||||||
try {
|
try (InputStream stream = new FileInputStream(localFile)) {
|
||||||
baseTranslations.putAll(parseTranslationFile(new FileInputStream(localFile)));
|
baseTranslations.putAll(parseTranslationFile(stream));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Failed to parse custom language file. Worth printing.
|
// Failed to parse custom language file. Worth printing.
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren