Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ryujinx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ryubing
Ryujinx
Commits
77ef82d9
Commit
77ef82d9
authored
2 months ago
by
GreemDev
Browse files
Options
Downloads
Patches
Plain Diff
misc: Cache LocalesJson when loading locale
parent
ba199f43
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Ryujinx.Common/Utilities/JsonHelper.cs
+8
-2
8 additions, 2 deletions
src/Ryujinx.Common/Utilities/JsonHelper.cs
src/Ryujinx/Common/LocaleManager.cs
+19
-28
19 additions, 28 deletions
src/Ryujinx/Common/LocaleManager.cs
with
27 additions
and
30 deletions
src/Ryujinx.Common/Utilities/JsonHelper.cs
+
8
−
2
View file @
77ef82d9
using
System
;
using
System.IO
;
using
System.Text
;
using
System.Text.Json
;
...
...
@@ -27,9 +28,14 @@ namespace Ryujinx.Common.Utilities
ReadCommentHandling
=
JsonCommentHandling
.
Skip
};
public
static
string
Serialize
<
T
>(
T
value
,
JsonTypeInfo
<
T
>
typeInfo
)
=>
JsonSerializer
.
Serialize
(
value
,
typeInfo
);
public
static
string
Serialize
<
T
>(
T
value
,
JsonTypeInfo
<
T
>
typeInfo
)
=>
JsonSerializer
.
Serialize
(
value
,
typeInfo
);
public
static
T
Deserialize
<
T
>(
string
value
,
JsonTypeInfo
<
T
>
typeInfo
)
=>
JsonSerializer
.
Deserialize
(
value
,
typeInfo
);
public
static
T
Deserialize
<
T
>(
string
value
,
JsonTypeInfo
<
T
>
typeInfo
)
=>
JsonSerializer
.
Deserialize
(
value
,
typeInfo
);
public
static
T
Deserialize
<
T
>(
ReadOnlySpan
<
byte
>
utf8Value
,
JsonTypeInfo
<
T
>
typeInfo
)
=>
JsonSerializer
.
Deserialize
<
T
>(
utf8Value
,
typeInfo
);
public
static
void
SerializeToFile
<
T
>(
string
filePath
,
T
value
,
JsonTypeInfo
<
T
>
typeInfo
)
{
...
...
This diff is collapsed.
Click to expand it.
src/Ryujinx/Common/LocaleManager.cs
+
19
−
28
View file @
77ef82d9
using
Gommon
;
using
Ryujinx.Ava.UI.ViewModels
;
using
Ryujinx.Common
;
using
Ryujinx.Common.Logging
;
...
...
@@ -7,12 +8,7 @@ using System;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.IO
;
using
System.Linq
;
using
System.Text.Encodings.Web
;
using
System.Text.Json
;
using
System.Text.Json.Serialization
;
using
System.Text.Unicode
;
namespace
Ryujinx.Ava.Common.Locale
{
...
...
@@ -147,39 +143,34 @@ namespace Ryujinx.Ava.Common.Locale
LocaleChanged
?.
Invoke
();
}
#
nullable
enable
private
static
LocalesJson
?
_localeData
;
#
nullable
disable
private
static
Dictionary
<
LocaleKeys
,
string
>
LoadJsonLanguage
(
string
languageCode
)
{
var
localeStrings
=
new
Dictionary
<
LocaleKeys
,
string
>();
string
fileData
=
EmbeddedResources
.
ReadAllText
(
$"Ryujinx/Assets/locales.json"
);
if
(
fileData
==
null
)
{
// We were unable to find file for that language code.
return
null
;
}
LocalesJson
json
=
JsonHelper
.
Deserialize
(
fileData
,
LocalesJsonContext
.
Default
.
LocalesJson
);
_localeData
??=
EmbeddedResources
.
ReadAllText
(
"Ryujinx/Assets/locales.json"
)
.
Into
(
it
=>
JsonHelper
.
Deserialize
(
it
,
LocalesJsonContext
.
Default
.
LocalesJson
));
foreach
(
LocalesEntry
locale
in
json
.
Locales
)
foreach
(
LocalesEntry
locale
in
_localeData
.
Value
.
Locales
)
{
if
(
locale
.
Translations
.
Count
!=
json
.
Languages
.
Count
)
if
(
locale
.
Translations
.
Count
!=
_localeData
.
Value
.
Languages
.
Count
)
{
Logger
.
Error
?.
Print
(
LogClass
.
UI
,
$"Locale key
{{{
locale
.
ID
}}}
is missing languages!"
);
throw
new
Exception
(
"Missing locale data!"
);
}
if
(
Enum
.
TryParse
<
LocaleKeys
>(
locale
.
ID
,
out
var
localeKey
))
{
if
(
locale
.
Translations
.
TryGetValue
(
languageCode
,
out
string
val
)
&&
val
!=
""
)
{
localeStrings
[
localeKey
]
=
val
;
}
else
{
locale
.
Translations
.
TryGetValue
(
"en_US"
,
out
val
);
localeStrings
[
localeKey
]
=
val
;
}
}
if
(!
Enum
.
TryParse
<
LocaleKeys
>(
locale
.
ID
,
out
var
localeKey
))
continue
;
localeStrings
[
localeKey
]
=
locale
.
Translations
.
TryGetValue
(
languageCode
,
out
string
val
)
&&
val
!=
string
.
Empty
?
val
:
locale
.
Translations
[
DefaultLanguageCode
];
}
return
localeStrings
;
...
...
@@ -200,5 +191,5 @@ namespace Ryujinx.Ava.Common.Locale
[
JsonSourceGenerationOptions
(
WriteIndented
=
true
)]
[
JsonSerializable
(
typeof
(
LocalesJson
))]
internal
partial
class
LocalesJsonContext
:
JsonSerializerContext
{
}
internal
partial
class
LocalesJsonContext
:
JsonSerializerContext
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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