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
51844b65
Commit
51844b65
authored
May 11, 2022
by
Melledy
Browse files
Merge branch 'development' into dev-quests
parents
e9d7d5d5
e3fd2eaa
Changes
44
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/utils/Language.java
View file @
51844b65
...
...
@@ -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
=
getLanguageFile
Stream
Descript
er
(
langCode
,
fallbackLanguageCode
);
var
fallbackLanguageCode
=
Utils
.
getLanguageCode
(
FALLBACK_LANGUAGE
);
var
description
=
getLanguageFileDescript
ion
(
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
getLanguageFile
Stream
Descript
er
(
String
languageCode
,
String
fallbackLanguageCode
)
{
private
static
LanguageStreamDescription
getLanguageFileDescript
ion
(
String
languageCode
,
String
fallbackLanguageCode
)
{
var
fileName
=
languageCode
+
".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
);
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
)
...
...
src/main/java/emu/grasscutter/utils/Utils.java
View file @
51844b65
...
...
@@ -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
();
Config
Container
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
))
{
...
...
src/main/resources/languages/en-US.json
View file @
51844b65
...
...
@@ -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"
:
{
...
...
src/main/resources/languages/zh-CN.json
View file @
51844b65
...
...
@@ -191,6 +191,7 @@
"language"
:
{
"current_language"
:
"当前语言是: %s"
,
"language_changed"
:
"语言切换至: %s"
,
"language_not_found"
:
"目前服务端没有这种语言: %s"
,
"description"
:
"显示或切换当前语言。"
},
"list"
:
{
...
...
Prev
1
2
3
Next
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