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