Skip to content

Commit

Permalink
Separate the localization code to Jeek.Avalonia.Localization
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyfish committed Jul 5, 2024
1 parent cb320e5 commit ab684b5
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 158 deletions.
5 changes: 3 additions & 2 deletions App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Jeek.Avalonia.Localization;

namespace HellDivers2OneKeyStratagem;

Expand All @@ -18,8 +19,8 @@ public override void OnFrameworkInitializationCompleted()
if (Settings.Locale == "")
Settings.Locale = CultureInfo.CurrentCulture.Name;

Localizer.Load();
Localizer.SetLanguage(Settings.Locale);
Localizer.SetLocalizer(new TabLocalizer(Path.Combine(AppSettings.DataDirectory, "Languages.tab")));
Localizer.Language = Settings.Locale;

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
Expand Down
5 changes: 3 additions & 2 deletions Dialogs/CalibrateVoiceDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HellDivers2OneKeyStratagem"
xmlns:l="clr-namespace:Jeek.Avalonia.Localization;assembly=Jeek.Avalonia.Localization"
mc:Ignorable="d"
x:DataType="local:CalibrateVoiceDialog"

TransparencyLevelHint="AcrylicBlur"
CanResize="False"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner"
Title="{local:Localize CalibrateRecognition}">
Title="{l:Localize CalibrateRecognition}">

<StackPanel Margin="20,10,20,10">
<local:MyHorizontalStackPanel>
<Label Name="MessageLabel" Content="飞鹰空袭" FontSize="32" />
</local:MyHorizontalStackPanel>
<local:MyHorizontalStackPanel HorizontalAlignment="Center">
<Button Content="{local:Localize Close}" Click="CloseButton_OnClick" />
<Button Content="{l:Localize Close}" Click="CloseButton_OnClick" />
</local:MyHorizontalStackPanel>
</StackPanel>
</Window>
11 changes: 6 additions & 5 deletions Dialogs/EditAliasesDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HellDivers2OneKeyStratagem"
xmlns:l="clr-namespace:Jeek.Avalonia.Localization;assembly=Jeek.Avalonia.Localization"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
TransparencyLevelHint="AcrylicBlur"
CanResize="False"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner"
Title="{local:Localize EditCustomName}">
Title="{l:Localize EditCustomName}">

<StackPanel Margin="20,10,20,10">
<local:MyHorizontalBlock>
<Label Content="{local:Localize PredefinedNames}" />
<Label Content="{l:Localize PredefinedNames}" />
<TextBox Name="SystemAliasesTextBox" Width="400" />
</local:MyHorizontalBlock>
<local:MyHorizontalBlock>
<Label Content="{local:Localize CustomNames}" />
<Label Content="{l:Localize CustomNames}" />
<TextBox Name="UserAliasesTextBox" Width="400" />
</local:MyHorizontalBlock>
<local:MyHorizontalStackPanel HorizontalAlignment="Center">
<Button Name="OkButton" Content="{local:Localize OK}" Click="OkButton_OnClick" />
<Button Name="CancelButton" Content="{local:Localize Cancel}" Click="CancelButton_OnClick" />
<Button Name="OkButton" Content="{l:Localize OK}" Click="OkButton_OnClick" />
<Button Name="CancelButton" Content="{l:Localize Cancel}" Click="CancelButton_OnClick" />
</local:MyHorizontalStackPanel>
</StackPanel>

Expand Down
3 changes: 2 additions & 1 deletion Dialogs/InfoWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:HellDivers2OneKeyStratagem"
xmlns:l="clr-namespace:Jeek.Avalonia.Localization;assembly=Jeek.Avalonia.Localization"

x:DataType="local:MainViewModel"

Expand All @@ -22,7 +23,7 @@
<StackPanel Margin="20,10,20,10" Spacing="10">
<Label Name="InfoLabel" Content="{Binding SpeechRecognizeResult}" />
<StackPanel Orientation="Horizontal" Spacing="10">
<Label Content="{local:Localize RecognitionConfidence}" />
<Label Content="{l:Localize RecognitionConfidence}" />
<NumericUpDown Value="{Binding SpeechConfidence}"
Increment="0.01" Maximum="1" Minimum="0.3" FormatString="F3" />
</StackPanel>
Expand Down
3 changes: 2 additions & 1 deletion Dialogs/MessageDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HellDivers2OneKeyStratagem"
xmlns:l="clr-namespace:Jeek.Avalonia.Localization;assembly=Jeek.Avalonia.Localization"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="HellDivers2OneKeyStratagem.MessageDialog"
TransparencyLevelHint="AcrylicBlur"
Expand All @@ -15,7 +16,7 @@
<Label Name="MessageLabel" Content="Message" />
</local:MyHorizontalStackPanel>
<local:MyHorizontalStackPanel HorizontalAlignment="Center">
<Button Name="OkButton" Content="{local:Localize OK}" Click="OkButton_OnClick" />
<Button Name="OkButton" Content="{l:Localize OK}" Click="OkButton_OnClick" />
</local:MyHorizontalStackPanel>
</StackPanel>
</Window>
5 changes: 3 additions & 2 deletions Dialogs/YesNoDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HellDivers2OneKeyStratagem"
xmlns:l="clr-namespace:Jeek.Avalonia.Localization;assembly=Jeek.Avalonia.Localization"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="HellDivers2OneKeyStratagem.YesNoDialog"
TransparencyLevelHint="AcrylicBlur"
Expand All @@ -15,8 +16,8 @@
<Label Name="MessageLabel" />
</local:MyHorizontalBlock>
<local:MyHorizontalStackPanel HorizontalAlignment="Center">
<Button Name="YesButton" Content="{local:Localize Yes}" Click="YesButton_OnClick" />
<Button Name="NoButton" Content="{local:Localize No}" Click="NoButton_OnClick" />
<Button Name="YesButton" Content="{l:Localize Yes}" Click="YesButton_OnClick" />
<Button Name="NoButton" Content="{l:Localize No}" Click="NoButton_OnClick" />
</local:MyHorizontalStackPanel>
</StackPanel>
</Window>
11 changes: 2 additions & 9 deletions HellDivers2OneKeyStratagem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@
</ItemGroup>

<ItemGroup>
<Compile Update="MainWindow\MainWindow.axaml.cs">
<DependentUpon>MainWindow.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="MainWindow\HotkeyStratagemPanel.axaml.cs">
<DependentUpon>HotkeyStratagemPanel.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<ProjectReference Include="..\Jeek.Avalonia.Localization\Jeek.Avalonia.Localization.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions HellDivers2OneKeyStratagem.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.11.34909.67
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HellDivers2OneKeyStratagem", "HellDivers2OneKeyStratagem.csproj", "{994DC79E-6FF4-4740-B364-DB4EFB111235}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jeek.Avalonia.Localization", "..\Jeek.Avalonia.Localization\Jeek.Avalonia.Localization.csproj", "{5ECD063F-821C-4720-B0AC-E1B7F3E6BDEC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{994DC79E-6FF4-4740-B364-DB4EFB111235}.Debug|Any CPU.Build.0 = Debug|Any CPU
{994DC79E-6FF4-4740-B364-DB4EFB111235}.Release|Any CPU.ActiveCfg = Release|Any CPU
{994DC79E-6FF4-4740-B364-DB4EFB111235}.Release|Any CPU.Build.0 = Release|Any CPU
{5ECD063F-821C-4720-B0AC-E1B7F3E6BDEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5ECD063F-821C-4720-B0AC-E1B7F3E6BDEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ECD063F-821C-4720-B0AC-E1B7F3E6BDEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ECD063F-821C-4720-B0AC-E1B7F3E6BDEC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
36 changes: 0 additions & 36 deletions Localization/LocalizeExtension.cs

This file was deleted.

78 changes: 0 additions & 78 deletions Localization/Localizer.cs

This file was deleted.

1 change: 1 addition & 0 deletions MainWindow/HotkeyStratagemPanel.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
using Jeek.Avalonia.Localization;

namespace HellDivers2OneKeyStratagem;

Expand Down
3 changes: 2 additions & 1 deletion MainWindow/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using CommunityToolkit.Mvvm.Input;
using EdgeTTS;
using GlobalHotKeys;
using Jeek.Avalonia.Localization;
using NAudio.Wave;

namespace HellDivers2OneKeyStratagem;
Expand Down Expand Up @@ -273,7 +274,7 @@ partial void OnCurrentLocaleChanged(string value)
Settings.Locale = value;
SettingsChanged = true;

Localizer.SetLanguage(value);
Localizer.Language = value;
}

private void InitUILanguages()
Expand Down
Loading

0 comments on commit ab684b5

Please sign in to comment.