mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 13:37:42 +00:00
Fix language fallback'ing
This commit is contained in:
parent
a269ff9563
commit
2416dd66e5
@ -48,11 +48,13 @@ public final class Language {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream file = Grasscutter.class.getResourceAsStream("/languages/" + fileName);
|
InputStream file = Grasscutter.class.getResourceAsStream("/languages/" + fileName);
|
||||||
if(file == null) {
|
String translationContents = Utils.readFromInputStream(file);
|
||||||
|
if(translationContents.equals("empty")) {
|
||||||
file = Grasscutter.class.getResourceAsStream("/languages/" + fallback);
|
file = Grasscutter.class.getResourceAsStream("/languages/" + fallback);
|
||||||
|
translationContents = Utils.readFromInputStream(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
languageData = Grasscutter.getGsonFactory().fromJson(Utils.readFromInputStream(file), JsonObject.class);
|
languageData = Grasscutter.getGsonFactory().fromJson(translationContents, JsonObject.class);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
Grasscutter.getLogger().warn("Failed to load language file: " + fileName, exception);
|
Grasscutter.getLogger().warn("Failed to load language file: " + fileName, exception);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ import io.netty.buffer.Unpooled;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedReturnValue", "BooleanMethodIsAlwaysInverted"})
|
@SuppressWarnings({"UnusedReturnValue", "BooleanMethodIsAlwaysInverted"})
|
||||||
@ -253,7 +255,9 @@ public final class Utils {
|
|||||||
* @param stream The input stream.
|
* @param stream The input stream.
|
||||||
* @return The string.
|
* @return The string.
|
||||||
*/
|
*/
|
||||||
public static String readFromInputStream(InputStream stream) {
|
public static String readFromInputStream(@Nullable InputStream stream) {
|
||||||
|
if(stream == null) return "empty";
|
||||||
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
|
||||||
String line; while ((line = reader.readLine()) != null) {
|
String line; while ((line = reader.readLine()) != null) {
|
||||||
@ -261,6 +265,8 @@ public final class Utils {
|
|||||||
} stream.close();
|
} stream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Grasscutter.getLogger().warn("Failed to read from input stream.");
|
Grasscutter.getLogger().warn("Failed to read from input stream.");
|
||||||
|
} catch (NullPointerException ignored) {
|
||||||
|
return "empty";
|
||||||
} return stringBuilder.toString();
|
} return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user