reformatted project
This commit is contained in:
@@ -14,17 +14,17 @@ public class Lang {
|
||||
}
|
||||
|
||||
public void addEntry(String key, String value) {
|
||||
entries.put(key, value);
|
||||
this.entries.put(key, value);
|
||||
}
|
||||
|
||||
public String getEntry(String key) {
|
||||
return entries.computeIfAbsent(key, s -> {
|
||||
return this.entries.computeIfAbsent(key, s -> {
|
||||
Logger.getLogger("localisation").warning(s + " is not known by translation files!");
|
||||
return new DummyLang().getEntry(s);
|
||||
});
|
||||
}
|
||||
|
||||
public String getLangId() {
|
||||
return langId;
|
||||
return this.langId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,35 +8,37 @@ import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Languages {
|
||||
private static Languages instance;
|
||||
public static final String defaultLanguage = "de_de";
|
||||
private static final Logger logger = Logger.getLogger("translation");
|
||||
|
||||
|
||||
private static Languages instance;
|
||||
private final Map<String, Lang> languages = new HashMap<>();
|
||||
|
||||
public static final String defaultLanguage = "de_de";
|
||||
private Languages() {
|
||||
this.readAll();
|
||||
}
|
||||
|
||||
public static Languages getInstance() {
|
||||
if(instance == null) instance = new Languages();
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Languages() {
|
||||
readAll();
|
||||
public Lang getLanguage(Player p) {
|
||||
return this.getLanguage(p.getSettings().locale().toString());
|
||||
}
|
||||
|
||||
public Lang getLanguage(Player p) {
|
||||
return getLanguage(p.getSettings().locale().toString()); // TODO funktioniert die locale noch?
|
||||
}
|
||||
public Lang getLanguage(String mapId) {
|
||||
return languages.computeIfAbsent(mapId.toLowerCase(), unused -> languages.computeIfAbsent(defaultLanguage, (key) -> new DummyLang()));
|
||||
return this.languages.computeIfAbsent(mapId.toLowerCase(), unused -> this.languages.computeIfAbsent(defaultLanguage, (key) -> new DummyLang()));
|
||||
}
|
||||
|
||||
private void readAll() {
|
||||
File locales = new File(Resource.LOCALES.getPath().toString());
|
||||
File[] files = Arrays.stream(locales.listFiles(File::canRead)).filter(file -> file.getName().endsWith("map.csv")).toArray(File[]::new);
|
||||
File[] files = Arrays.stream(Objects.requireNonNull(locales.listFiles(File::canRead)))
|
||||
.filter(file -> file.getName().endsWith("map.csv"))
|
||||
.toArray(File[]::new);
|
||||
|
||||
if(files.length == 0) {
|
||||
logger.warning("Failed to find any Language-files!");
|
||||
@@ -66,20 +68,22 @@ public class Languages {
|
||||
index++;
|
||||
if(langId.endsWith("map")) continue;
|
||||
|
||||
languages.computeIfAbsent(langId, Lang::new);
|
||||
Lang lang = languages.get(langId);
|
||||
this.languages.computeIfAbsent(langId, Lang::new);
|
||||
Lang lang = this.languages.get(langId);
|
||||
langColumn.put(index, lang);
|
||||
languages.put(langId, lang);
|
||||
this.languages.put(langId, lang);
|
||||
}
|
||||
|
||||
} else if(columns[0].startsWith("ns:")) {
|
||||
if(!computedFileHeader) throw new IllegalStateException("Cannot compute namespace data before file-header was red!");
|
||||
if(!computedFileHeader)
|
||||
throw new IllegalStateException("Cannot compute namespace data before file-header was red!");
|
||||
namespace = columns[0].split(":")[1];
|
||||
|
||||
} else {
|
||||
|
||||
// file contents
|
||||
if(!computedFileHeader) throw new IllegalStateException("Cannot compute translation data before file-header was red!");
|
||||
if(!computedFileHeader)
|
||||
throw new IllegalStateException("Cannot compute translation data before file-header was red!");
|
||||
int index = 0;
|
||||
String mapId = "";
|
||||
for(String translation : columns) {
|
||||
@@ -97,7 +101,7 @@ public class Languages {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
logger.warning("Exception while parsing lang-files: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user