Commit 51844b65 authored by Melledy's avatar Melledy
Browse files

Merge branch 'development' into dev-quests

parents e9d7d5d5 e3fd2eaa
......@@ -10,6 +10,8 @@ import java.io.InputStream;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import static emu.grasscutter.Configuration.*;
public final class Language {
private static final Map<String, Language> cachedLanguages = new ConcurrentHashMap<>();
......@@ -27,8 +29,8 @@ public final class Language {
return cachedLanguages.get(langCode);
}
var fallbackLanguageCode = Utils.getLanguageCode(Grasscutter.getConfig().DefaultLanguage);
var description = getLanguageFileStreamDescripter(langCode, fallbackLanguageCode);
var fallbackLanguageCode = Utils.getLanguageCode(FALLBACK_LANGUAGE);
var description = getLanguageFileDescription(langCode, fallbackLanguageCode);
var actualLanguageCode = description.getLanguageCode();
Language languageInst;
......@@ -111,35 +113,31 @@ public final class Language {
* @param languageCode The name of the language code.
* @param fallbackLanguageCode The name of the fallback language code.
*/
private static LanguageStreamDescription getLanguageFileStreamDescripter(String languageCode, String fallbackLanguageCode) {
private static LanguageStreamDescription getLanguageFileDescription(String languageCode, String fallbackLanguageCode) {
var fileName = languageCode + ".json";
var fallback = fallbackLanguageCode + ".json";
String actualLanguageCode = languageCode;
if (cachedLanguages.containsKey(actualLanguageCode)) {
return new LanguageStreamDescription(actualLanguageCode, null);
}
InputStream file = Grasscutter.class.getResourceAsStream("/languages/" + fileName);
if (file == null) { // Provided fallback language.
Grasscutter.getLogger().warn("Failed to load language file: " + fileName + ", falling back to: " + fallback);
actualLanguageCode = fallbackLanguageCode;
if (cachedLanguages.containsKey(actualLanguageCode)) {
return new LanguageStreamDescription(actualLanguageCode, null);
}
file = Grasscutter.class.getResourceAsStream("/languages/" + fallback);
Grasscutter.getLogger().warn("Failed to load language file: " + fileName + ", falling back to: " + fallback);
}
if(file == null) { // Fallback the fallback language.
Grasscutter.getLogger().warn("Failed to load language file: " + fallback + ", falling back to: en-US.json");
actualLanguageCode = "en-US";
if (cachedLanguages.containsKey(actualLanguageCode)) {
return new LanguageStreamDescription(actualLanguageCode, null);
}
file = Grasscutter.class.getResourceAsStream("/languages/en-US.json");
Grasscutter.getLogger().warn("Failed to load language file: " + fallback + ", falling back to: en-US.json");
}
if(file == null)
......
......@@ -11,7 +11,6 @@ import java.util.Map;
import java.util.Random;
import java.util.Locale;
import emu.grasscutter.Config;
import emu.grasscutter.Grasscutter;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
......@@ -175,12 +174,12 @@ public final class Utils {
* Checks for required files and folders before startup.
*/
public static void startupCheck() {
Config config = Grasscutter.getConfig();
ConfigContainer config = Grasscutter.getConfig();
Logger logger = Grasscutter.getLogger();
boolean exit = false;
String resourcesFolder = config.RESOURCE_FOLDER;
String dataFolder = config.DATA_FOLDER;
String resourcesFolder = config.folderStructure.resources;
String dataFolder = config.folderStructure.data;
// Check for resources folder.
if(!fileExists(resourcesFolder)) {
......
......@@ -191,6 +191,7 @@
"language": {
"current_language": "current language is %s",
"language_changed": "language changed to %s",
"language_not_found": "currently, server does not have that language: %s",
"description": "display or change current language"
},
"list": {
......
......@@ -191,6 +191,7 @@
"language": {
"current_language": "当前语言是: %s",
"language_changed": "语言切换至: %s",
"language_not_found": "目前服务端没有这种语言: %s",
"description": "显示或切换当前语言。"
},
"list": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment