mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Always use UTF-8 for loading translations
(cherry picked from commit 624b3a449b5746cee84557992b9b217ac135cf50)
This commit is contained in:
parent
f4d03291c5
commit
d5828861de
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user