Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grasscutter
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
ziqian zhang
Grasscutter
Commits
549471b7
Commit
549471b7
authored
3 years ago
by
KingRainbow44
Browse files
Options
Downloads
Patches
Plain Diff
Fix language fallback'ing
parent
50307ea3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/emu/grasscutter/utils/Language.java
+4
-2
4 additions, 2 deletions
src/main/java/emu/grasscutter/utils/Language.java
src/main/java/emu/grasscutter/utils/Utils.java
+7
-1
7 additions, 1 deletion
src/main/java/emu/grasscutter/utils/Utils.java
with
11 additions
and
3 deletions
src/main/java/emu/grasscutter/utils/Language.java
+
4
−
2
View file @
549471b7
...
@@ -48,11 +48,13 @@ public final class Language {
...
@@ -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
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/emu/grasscutter/utils/Utils.java
+
7
−
1
View file @
549471b7
...
@@ -18,6 +18,8 @@ import io.netty.buffer.Unpooled;
...
@@ -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 {
...
@@ -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 {
...
@@ -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
();
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment