Skip to content

Commit b9066ac

Browse files
committed
✨ added i18n native handling, lang selector
1 parent d6d05d1 commit b9066ac

File tree

266 files changed

+338
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+338
-20
lines changed

Biyori/App.xaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<Application x:Class="Biyori.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:local="clr-namespace:Biyori">
4+
xmlns:local="clr-namespace:Biyori"
5+
xmlns:languages="clr-namespace:Biyori.Lib.Languages">
56
<Application.Resources>
67
<ResourceDictionary>
78
<ResourceDictionary.MergedDictionaries>
89
<ResourceDictionary Source="pack://application:,,,/Lib/Styles/App.styles.xaml" />
9-
<ResourceDictionary Source="pack://application:,,,/Lib/Languages/Languages.xaml" />
10+
<languages:Languages Source="pack://application:,,,/Lib/Languages/Languages.xaml" />
1011
</ResourceDictionary.MergedDictionaries>
1112
</ResourceDictionary>
1213
</Application.Resources>

Biyori/App.xaml.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
using System;
1+
using Biyori.Components.Loading;
2+
using Biyori.Settings;
3+
using Biyori.Settings.Frames;
4+
using System;
25
using System.Collections.Generic;
36
using System.Configuration;
47
using System.Data;
8+
using System.Diagnostics;
59
using System.Linq;
610
using System.Threading.Tasks;
711
using System.Windows;
12+
using System.Windows.Navigation;
813

914
namespace Biyori
1015
{
@@ -16,13 +21,18 @@ public partial class App : Application
1621
public static readonly ServiceProviderCollector ServiceProvider = new ServiceProviderCollector();
1722
public App() : base()
1823
{
24+
App.ServiceProvider.ScanCurrent();
1925
}
2026
protected override void OnStartup(StartupEventArgs e)
2127
{
2228
base.OnStartup(e);
2329

24-
App.ServiceProvider.ScanCurrent();
25-
new MainWindow().Show();
30+
31+
var languageInstance = Lib.Languages.Languages.Instance();
32+
languageInstance.Initialize();
33+
Debug.WriteLine("Currently active Language: " + App.ServiceProvider.GetProvider<SettingsProviderService>()?.GetConfig<ApplicationSettings>()?.SelectedLanguage.DisplayName);
34+
new LoadingWIndow().Show();
2635
}
36+
2737
}
2838
}

Biyori/Assets/logo_image.png

526 KB

Biyori/Biyori.csproj

+23
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,13 @@
199199
<Compile Include="Components\LeftNavigation\LeftNavigationControl.xaml.cs">
200200
<DependentUpon>LeftNavigationControl.xaml</DependentUpon>
201201
</Compile>
202+
<Compile Include="Components\Loading\LoadingWIndow.xaml.cs">
203+
<DependentUpon>LoadingWIndow.xaml</DependentUpon>
204+
</Compile>
202205
<Compile Include="Lib\Controls\CardControl.cs" />
206+
<Compile Include="Lib\Languages\Languages.xaml.cs">
207+
<DependentUpon>Languages.xaml</DependentUpon>
208+
</Compile>
203209
<Compile Include="Lib\WPF\MarginSetter.cs" />
204210
<Compile Include="Lib\WPF\Spacing.cs" />
205211
<Compile Include="ServiceProvider.cs" />
@@ -225,10 +231,18 @@
225231
<SubType>Designer</SubType>
226232
<Generator>MSBuild:Compile</Generator>
227233
</Page>
234+
<Page Include="Components\Loading\LoadingWIndow.xaml">
235+
<SubType>Designer</SubType>
236+
<Generator>MSBuild:Compile</Generator>
237+
</Page>
228238
<Page Include="Lib\Controls\CardControl.style.xaml">
229239
<SubType>Designer</SubType>
230240
<Generator>MSBuild:Compile</Generator>
231241
</Page>
242+
<Page Include="Lib\Languages\de-de.lang.xaml">
243+
<Generator>MSBuild:Compile</Generator>
244+
<SubType>Designer</SubType>
245+
</Page>
232246
<Page Include="Lib\Languages\en-us.lang.xaml">
233247
<SubType>Designer</SubType>
234248
<Generator>MSBuild:Compile</Generator>
@@ -324,6 +338,15 @@
324338
<Folder Include="Frames\NowPlaying\" />
325339
<Folder Include="Frames\TorrentList\" />
326340
</ItemGroup>
341+
<ItemGroup>
342+
<Resource Include="Lib\Languages\Images\Flags\us.png" />
343+
</ItemGroup>
344+
<ItemGroup>
345+
<Resource Include="Assets\logo_image.png" />
346+
</ItemGroup>
347+
<ItemGroup>
348+
<Resource Include="Lib\Languages\Images\Flags\de.png" />
349+
</ItemGroup>
327350
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
328351
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
329352
<PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<Window x:Class="Biyori.Components.Loading.LoadingWIndow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:Biyori.Components.Loading"
7+
mc:Ignorable="d"
8+
WindowStyle="None"
9+
AllowsTransparency="True"
10+
Background="Transparent"
11+
WindowStartupLocation="CenterScreen"
12+
Title="Loading Biyori..." Height="420" Width="680">
13+
<Grid Margin="18" PreviewMouseDown="Grid_PreviewMouseDown">
14+
<Border BorderThickness="1" BorderBrush="#ddd" Background="#fff" CornerRadius="8">
15+
<Border.Effect>
16+
<DropShadowEffect BlurRadius="12" ShadowDepth="0" Direction="0" Color="#000" Opacity=".55" />
17+
</Border.Effect>
18+
</Border>
19+
<Border CornerRadius="8" ClipToBounds="True">
20+
<Grid>
21+
<Grid.RowDefinitions>
22+
<RowDefinition Height="*"/>
23+
<RowDefinition Height="32"/>
24+
</Grid.RowDefinitions>
25+
<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
26+
<Image
27+
RenderOptions.BitmapScalingMode="HighQuality"
28+
VerticalAlignment="Center" Height="300" HorizontalAlignment="Center" Margin="0,0,24,0" Source="pack://application:,,,/Assets/logo_image.png"/>
29+
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Width="200">
30+
<TextBlock Text="Biyori" HorizontalAlignment="Center" FontSize="32" Opacity=".8" />
31+
<Separator Width="86" Margin="0, 12" Opacity=".5" />
32+
<TextBlock Text="Loading" HorizontalAlignment="Center" Opacity=".8" />
33+
</StackPanel>
34+
</StackPanel>
35+
<Separator Grid.Row="1" VerticalAlignment="Top" Margin="20,0" Opacity=".5" />
36+
<Grid Grid.Row="1" Margin="24,0">
37+
<Grid.ColumnDefinitions>
38+
<ColumnDefinition Width="Auto"/>
39+
<ColumnDefinition Width="*"/>
40+
<ColumnDefinition Width="Auto"/>
41+
</Grid.ColumnDefinitions>
42+
<StackPanel Grid.Column="0" Orientation="Horizontal">
43+
<TextBlock Text="Loading Status" VerticalAlignment="Center"/>
44+
</StackPanel>
45+
<StackPanel Grid.Column="2" Orientation="Horizontal">
46+
<TextBlock Text="{DynamicResource Name}" VerticalAlignment="Center"/>
47+
</StackPanel>
48+
</Grid>
49+
</Grid>
50+
</Border>
51+
</Grid>
52+
</Window>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Timers;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
using System.Windows.Documents;
11+
using System.Windows.Input;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Shapes;
15+
16+
namespace Biyori.Components.Loading
17+
{
18+
/// <summary>
19+
/// Interaction logic for LoadingWIndow.xaml
20+
/// </summary>
21+
public partial class LoadingWIndow : Window
22+
{
23+
public LoadingWIndow()
24+
{
25+
InitializeComponent();
26+
}
27+
protected override void OnInitialized(EventArgs e)
28+
{
29+
base.OnInitialized(e);
30+
31+
//var languageInstance = Lib.Languages.Languages.Instance();
32+
//languageInstance.Initialize();
33+
34+
Dispatcher.BeginInvoke((Action)(() =>
35+
{
36+
this.Hide();
37+
new MainWindow().Show();
38+
this.Close();
39+
}));
40+
}
41+
private void Grid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
42+
{
43+
if (e.ChangedButton == MouseButton.Left)
44+
this.DragMove();
45+
}
46+
}
47+
}

Biyori/Lib/Controls/CardControl.style.xaml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
<Style TargetType="{x:Type local:CardControl}">
66
<Setter Property="Focusable" Value="False"/>
7+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
78
<Setter Property="Template">
89
<Setter.Value>
910
<ControlTemplate TargetType="{x:Type local:CardControl}">
@@ -12,6 +13,7 @@
1213
<Border.Style>
1314

1415
<Style TargetType="Border">
16+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
1517
<Setter Property="Focusable" Value="False"/>
1618
<Setter Property="Padding" Value="10"/>
1719
<Setter Property="Background" Value="#ffffff" />
643 Bytes
408 Bytes
604 Bytes
591 Bytes
643 Bytes
600 Bytes
497 Bytes
488 Bytes
428 Bytes
506 Bytes
647 Bytes
403 Bytes
673 Bytes
524 Bytes
663 Bytes
589 Bytes
593 Bytes
585 Bytes
504 Bytes
449 Bytes
497 Bytes
462 Bytes
457 Bytes
675 Bytes
486 Bytes
611 Bytes
639 Bytes
500 Bytes
593 Bytes
526 Bytes
631 Bytes
512 Bytes
443 Bytes
514 Bytes
600 Bytes
628 Bytes
398 Bytes
625 Bytes
528 Bytes
614 Bytes
521 Bytes
367 Bytes
453 Bytes
586 Bytes
450 Bytes
525 Bytes
472 Bytes
483 Bytes
477 Bytes
439 Bytes
563 Bytes
529 Bytes
608 Bytes
428 Bytes
476 Bytes
545 Bytes
572 Bytes
495 Bytes
620 Bytes
508 Bytes
582 Bytes
500 Bytes
429 Bytes
465 Bytes
508 Bytes
496 Bytes
653 Bytes
469 Bytes
592 Bytes
479 Bytes
532 Bytes
489 Bytes
610 Bytes
648 Bytes
552 Bytes
474 Bytes
545 Bytes
489 Bytes
599 Bytes
637 Bytes
594 Bytes
545 Bytes
490 Bytes
463 Bytes
470 Bytes
493 Bytes
480 Bytes
488 Bytes
537 Bytes
487 Bytes
630 Bytes
493 Bytes
509 Bytes
516 Bytes
645 Bytes
527 Bytes
673 Bytes
537 Bytes
524 Bytes
487 Bytes
432 Bytes
430 Bytes
481 Bytes
431 Bytes
503 Bytes
658 Bytes
515 Bytes
512 Bytes
532 Bytes
420 Bytes
637 Bytes
473 Bytes
420 Bytes
569 Bytes
510 Bytes
549 Bytes
656 Bytes
577 Bytes
604 Bytes
561 Bytes
592 Bytes
486 Bytes
643 Bytes
616 Bytes
563 Bytes
517 Bytes
520 Bytes
537 Bytes
627 Bytes
466 Bytes
628 Bytes
508 Bytes
481 Bytes
465 Bytes
419 Bytes
432 Bytes
380 Bytes
566 Bytes
448 Bytes
453 Bytes
628 Bytes
664 Bytes
474 Bytes
483 Bytes
492 Bytes
588 Bytes
597 Bytes
655 Bytes
569 Bytes
614 Bytes
420 Bytes
496 Bytes
542 Bytes
529 Bytes
574 Bytes
571 Bytes
584 Bytes
647 Bytes
591 Bytes
537 Bytes
602 Bytes
482 Bytes
508 Bytes
453 Bytes
512 Bytes
443 Bytes
527 Bytes
572 Bytes
639 Bytes
478 Bytes
519 Bytes
397 Bytes
498 Bytes
593 Bytes
538 Bytes
569 Bytes
374 Bytes
689 Bytes
657 Bytes
556 Bytes
472 Bytes
554 Bytes
550 Bytes
473 Bytes
450 Bytes
545 Bytes
495 Bytes
423 Bytes
420 Bytes
533 Bytes
551 Bytes
624 Bytes
608 Bytes
649 Bytes
492 Bytes
542 Bytes
468 Bytes
645 Bytes
510 Bytes
512 Bytes
562 Bytes
436 Bytes
502 Bytes
532 Bytes
527 Bytes
513 Bytes
584 Bytes
501 Bytes
422 Bytes
643 Bytes
624 Bytes
570 Bytes
527 Bytes
562 Bytes
452 Bytes
496 Bytes
638 Bytes
514 Bytes
593 Bytes
495 Bytes
426 Bytes
492 Bytes
617 Bytes
536 Bytes
465 Bytes
642 Bytes
446 Bytes
531 Bytes
571 Bytes
609 Bytes
532 Bytes
515 Bytes
553 Bytes
577 Bytes
528 Bytes
630 Bytes
616 Bytes
474 Bytes
604 Bytes
652 Bytes
554 Bytes
476 Bytes
413 Bytes
593 Bytes
642 Bytes
500 Bytes
574 Bytes

Biyori/Lib/Languages/Languages.xaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="Biyori.Lib.Languages.Languages"
34
xmlns:local="clr-namespace:Biyori.Lib.Languages">
45
<ResourceDictionary.MergedDictionaries>
6+
<ResourceDictionary Source="pack://application:,,,/Lib/Languages/de-de.lang.xaml" />
57
<ResourceDictionary Source="pack://application:,,,/Lib/Languages/en-us.lang.xaml" />
68
</ResourceDictionary.MergedDictionaries>
79
</ResourceDictionary>
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using Biyori.Settings;
2+
using Biyori.Settings.Frames;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Windows.Controls;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows;
10+
using System.Windows.Media;
11+
12+
namespace Biyori.Lib.Languages
13+
{
14+
public partial class Languages : ResourceDictionary
15+
{
16+
public static ApplicationLanguage DefaultAppLanguage { get; set; }
17+
public Languages()
18+
{
19+
}
20+
public static Languages Instance()
21+
{
22+
return Application.Current.Resources.MergedDictionaries.FirstOrDefault(x => x.Source.PathAndQuery.ToLower().EndsWith("languages.xaml")) as Languages;
23+
}
24+
public void Initialize()
25+
{
26+
var provider = App.ServiceProvider.GetProvider<SettingsProviderService>();
27+
var appConfig = provider.GetConfig<ApplicationSettings>();
28+
var selectedLanguageResource = appConfig?.SelectedLanguage?.Name != null &&
29+
this.MergedDictionaries.Where(x => x.Contains("LangKey") && x["LangKey"].ToString() == appConfig.SelectedLanguage.Name).Count() > 0 ?
30+
this.getLanguageResource(appConfig.SelectedLanguage.Name) :
31+
this.getLanguageResource("en-us");
32+
var selectedLanguage = new ApplicationLanguage()
33+
{
34+
ImageUrl = selectedLanguageResource["ImageUrl"]?.ToString(),
35+
DisplayName = selectedLanguageResource["DisplayName"]?.ToString(),
36+
Name = selectedLanguageResource["LangKey"]?.ToString(),
37+
};
38+
appConfig.Languages.AddRange(this.getLanguages());
39+
provider.UpdateConfig(appConfig, true);
40+
this.MergedDictionaries.Clear();
41+
this.MergedDictionaries.Add(selectedLanguageResource);
42+
}
43+
44+
private ApplicationLanguage getDefaultLanguage()
45+
{
46+
return this.getLanguageByLangKey("en-us");
47+
}
48+
private ApplicationLanguage getLanguageByLangKey(string langKey)
49+
{
50+
51+
var resx = this
52+
.MergedDictionaries.Where(x => x.Source?.PathAndQuery?.ToLower().EndsWith(".lang.xaml") == true).ToList();
53+
var resource = resx.Find(x => x["LangKey"]?.ToString() == langKey);
54+
var lang = new ApplicationLanguage()
55+
{
56+
ImageUrl = resource["ImageUrl"]?.ToString(),
57+
DisplayName = resource["DisplayName"]?.ToString(),
58+
Name = resource["LangKey"]?.ToString(),
59+
};
60+
return lang;
61+
}
62+
private IEnumerable<ApplicationLanguage> getLanguages()
63+
{
64+
var languages = new List<ApplicationLanguage>();
65+
languages.AddRange(this.MergedDictionaries.Where(x => x.Source?.PathAndQuery?.ToLower().EndsWith(".lang.xaml") == true).Select(resource => new ApplicationLanguage()
66+
{
67+
ImageUrl = resource["ImageUrl"]?.ToString(),
68+
DisplayName = resource["Name"]?.ToString(),
69+
Name = resource["LangKey"]?.ToString(),
70+
}));
71+
return languages;
72+
}
73+
private ResourceDictionary getLanguageResource(string langKey)
74+
{
75+
var resx = this
76+
.MergedDictionaries.Where(x => x.Source?.PathAndQuery?.ToLower().EndsWith(".lang.xaml") == true).ToList();
77+
return resx.Find(x => x["LangKey"]?.ToString() == langKey);
78+
}
79+
}
80+
}

Biyori/Lib/Languages/de-de.lang.xaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:system="clr-namespace:System;assembly=mscorlib"
4+
xmlns:local="clr-namespace:Biyori.Lib.Languages">
5+
<system:String x:Key="LangKey">de-de</system:String>
6+
<system:String x:Key="ImageUrl">pack://application:,,,/Lib/Languages/Images/Flags/de.png</system:String>
7+
<system:String x:Key="Name">Deutsch</system:String>
8+
<system:String x:Key="Name_Simplified">Deutschland</system:String>
9+
<system:String x:Key="ShortName">DE</system:String>
10+
<system:String x:Key="languageSelect">Sprache auswählen</system:String>
11+
<system:String x:Key="searchPlaceholder">Suche Anime in deiner Liste oder Kitsu</system:String>
12+
</ResourceDictionary>

Biyori/Lib/Languages/en-us.lang.xaml

+6
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:system="clr-namespace:System;assembly=mscorlib"
44
xmlns:local="clr-namespace:Biyori.Lib.Languages">
5+
<system:String x:Key="LangKey">en-us</system:String>
6+
<system:String x:Key="ImageUrl">pack://application:,,,/Lib/Languages/Images/Flags/us.png</system:String>
7+
<system:String x:Key="Name">English (United States)</system:String>
8+
<system:String x:Key="Name_Simplified">English</system:String>
9+
<system:String x:Key="ShortName">EN</system:String>
10+
<system:String x:Key="languageSelect">Select Language</system:String>
511
<system:String x:Key="searchPlaceholder">Filter list or search Kitsu</system:String>
612
</ResourceDictionary>

Biyori/Lib/Styles/App.styles.xaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
xmlns:local="clr-namespace:Biyori.Lib.Styles">
44
<Style x:Key="TextboxPlaceholderStyle" TargetType="TextBlock">
55
<Setter Property="VerticalAlignment" Value="Center"/>
6-
<Setter Property="FontStyle" Value="Italic" />
7-
<Setter Property="FontSize" Value="12" />
6+
<Setter Property="FontStyle" Value="Normal" />
7+
<Setter Property="Opacity" Value=".65"/>
8+
<Setter Property="FontSize" Value="11" />
89
</Style>
910
<Style TargetType="Window">
1011
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />

Biyori/Lib/Styles/Buttons.styles.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Setter Property="OverridesDefaultStyle" Value="True"/>
77
<Setter Property="Margin" Value="0" />
88
<Setter Property="Padding" Value="8, 6" />
9-
<!--<Setter Property="FocusVisualStyle" Value="{StaticResource MyFocusVisual}" />-->
9+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
1010
<Setter Property="Background" Value="#fafafa"/>
1111
<Setter Property="BorderBrush" Value="#e0e0e0"/>
1212
<Setter Property="BorderThickness" Value="1"/>

Biyori/MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</Grid>
3131
</Border>
3232
<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
33-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" wpf:MarginSetter.Margin="2, 0" wpf:MarginSetter.LastItemMargin="2, 0, 0, 0">
33+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Margin="8,0,0,0" wpf:MarginSetter.Margin="2, 0" wpf:MarginSetter.LastItemMargin="2, 0, 0, 0">
3434
<Button Style="{StaticResource NavButtons}" HorizontalAlignment="Left" VerticalAlignment="Center">Sync</Button>
3535
<Grid>
3636
<Separator Background="LightGray" Margin="0, 14" Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" VerticalAlignment="Stretch"></Separator>

0 commit comments

Comments
 (0)