Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
bf0d0177
Commit
bf0d0177
authored
May 07, 2022
by
Secretboy
Committed by
Melledy
May 06, 2022
Browse files
Update Language.java
parent
f9b5478c
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/utils/Language.java
View file @
bf0d0177
...
@@ -39,18 +39,47 @@ public final class Language {
...
@@ -39,18 +39,47 @@ public final class Language {
}
}
/**
/**
*
Reads a file and
creates a language instance.
* creates a language instance.
* @param fileName The name of the language file.
* @param fileName The name of the language file.
*/
*/
private
Language
(
String
fileName
)
{
private
Language
(
String
fileName
)
{
@Nullable
JsonObject
languageData
=
null
;
@Nullable
JsonObject
languageData
=
null
;
languageData
=
loadLanguage
(
fileName
);
if
(
languageData
==
null
)
{
Grasscutter
.
getLogger
().
info
(
"Now switch to default language"
);
languageData
=
loadDefaultLanguage
();
}
assert
languageData
!=
null
:
"languageData is null"
;
this
.
languageData
=
languageData
;
}
/**
* Load default language file and creates a language instance.
* @return language data
*/
private
JsonObject
loadDefaultLanguage
()
{
var
fileName
=
Grasscutter
.
getConfig
().
DefaultLanguage
.
toLanguageTag
()
+
".json"
;
return
loadLanguage
(
fileName
);
}
/**
* Reads a file and creates a language instance.
* @param fileName The name of the language file.
* @return language data
*/
private
JsonObject
loadLanguage
(
String
fileName
)
{
@Nullable
JsonObject
languageData
=
null
;
try
{
try
{
InputStream
file
=
Grasscutter
.
class
.
getResourceAsStream
(
"/languages/"
+
fileName
);
InputStream
file
=
Grasscutter
.
class
.
getResourceAsStream
(
"/languages/"
+
fileName
);
languageData
=
Grasscutter
.
getGsonFactory
().
fromJson
(
Utils
.
readFromInputStream
(
file
),
JsonObject
.
class
);
languageData
=
Grasscutter
.
getGsonFactory
().
fromJson
(
Utils
.
readFromInputStream
(
file
),
JsonObject
.
class
);
}
catch
(
Exception
exception
)
{
}
catch
(
Exception
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to load language file: "
+
fileName
,
exception
);
Grasscutter
.
getLogger
().
warn
(
"Failed to load language file: "
+
fileName
);
}
this
.
languageData
=
languageData
;
}
return
languageData
;
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment