1
0
mirror of synced 2024-11-24 15:00:16 +01:00

Add support for zh-hant

Refactor to make language specifiable in appsettings
This commit is contained in:
asesidaa 2024-01-24 11:12:15 +08:00
parent 16cc17246f
commit ccd3b22b41
6 changed files with 91 additions and 12 deletions

View File

@ -0,0 +1,35 @@
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="dashboard" xml:space="preserve">
<value>Dashboard</value>
</data>
<data name="users" xml:space="preserve">
<value>Users</value>
</data>
<data name="edit profile" xml:space="preserve">
<value>Edit Profile</value>
</data>
<data name="user" xml:space="preserve">
<value>User</value>
</data>
<data name="view play data" xml:space="preserve">
<value>View Play Data</value>
</data>
<data name="high scores" xml:space="preserve">
<value>High Scores</value>
</data>
<data name="dani dojo" xml:space="preserve">
<value>Dani Dojo</value>
</data>
</root>

View File

@ -0,0 +1,8 @@
namespace TaikoWebUI.Settings;
public class Language
{
public string CultureCode { get; set; } = "en-US";
public string DisplayName { get; set; } = "English";
}

View File

@ -2,10 +2,11 @@
public class WebUiSettings public class WebUiSettings
{ {
public bool LoginRequired { get; set; } public bool LoginRequired { get; set; }
public bool OnlyAdmin { get; set; } public bool OnlyAdmin { get; set; }
public int BoundAccessCodeUpperLimit { get; set; } public int BoundAccessCodeUpperLimit { get; set; }
public bool RegisterWithLastPlayTime { get; set; } public bool RegisterWithLastPlayTime { get; set; }
public bool AllowUserDelete { get; set; } public bool AllowUserDelete { get; set; }
public bool AllowFreeProfileEditing { get; set; } public bool AllowFreeProfileEditing { get; set; }
public Language[] SupportedLanguages { get; set; } = Array.Empty<Language>();
} }

View File

@ -1,6 +1,9 @@
@using System.Globalization; @using System.Globalization;
@using Microsoft.Extensions.Options
@using TaikoWebUI.Settings
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IJSRuntime JSRuntime @inject IJSRuntime JSRuntime
@inject IOptions<WebUiSettings> Settings
<MudMenu Icon="@Icons.Material.Filled.Language" Color="Color.Inherit"> <MudMenu Icon="@Icons.Material.Filled.Language" Color="Color.Inherit">
@foreach (var culture in SupportedCultures) @foreach (var culture in SupportedCultures)
@ -11,12 +14,21 @@
@code{ @code{
public readonly Dictionary<CultureInfo, string> SupportedCultures = new() public Dictionary<CultureInfo, string> SupportedCultures = new();
protected override void OnInitialized()
{ {
{ new CultureInfo("en-US"), "English" }, base.OnInitialized();
{ new CultureInfo("zh-Hans"), "简体中文" }, foreach (var language in Settings.Value.SupportedLanguages)
{ new CultureInfo("ja"), "日本語" }, {
}; SupportedCultures.Add(new CultureInfo(language.CultureCode), language.DisplayName);
}
if (SupportedCultures.Count == 0)
{
SupportedCultures.Add(new CultureInfo("en-US"), "English");
}
}
private void RequestCultureChange(CultureInfo newCulture) private void RequestCultureChange(CultureInfo newCulture)
{ {

View File

@ -87,6 +87,11 @@
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<CustomToolNamespace>LocalizationResource</CustomToolNamespace> <CustomToolNamespace>LocalizationResource</CustomToolNamespace>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Update="Localization\LocalizationResource.zh-Hant.resx">
<SubType>Designer</SubType>
<Generator>ResXFileCodeGenerator</Generator>
<CustomToolNamespace>LocalizationResource</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -5,6 +5,24 @@
"BoundAccessCodeUpperLimit": "3", "BoundAccessCodeUpperLimit": "3",
"RegisterWithLastPlayTime": "false", "RegisterWithLastPlayTime": "false",
"AllowUserDelete": "true", "AllowUserDelete": "true",
"AllowFreeProfileEditing": "true" "AllowFreeProfileEditing": "true",
"SupportedLanguages": [
{
"CultureCode": "en-US",
"DisplayName": "English"
},
{
"CultureCode": "zh-Hans",
"DisplayName": "简体中文"
},
{
"CultureCode": "zh-Hant",
"DisplayName": "繁體中文"
},
{
"CultureCode": "ja",
"DisplayName": "日本語"
}
]
} }
} }