Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi-language support (Chinese, English and French) #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions elaphureLink.Wpf/Pages/ExitConfirmDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:language="clr-namespace:elaphureLink.Wpf.Properties.languages"

PrimaryButtonText="Exit"
SecondaryButtonText="Cancel"
PrimaryButtonText="{x:Static language:i18n.exit}"
SecondaryButtonText="{x:Static language:i18n.cancel}"
DefaultButton="Secondary">

<TextBlock Text="Are you sure you want to exit?" TextAlignment="Center" VerticalAlignment="Center" FontSize="26"/>
<TextBlock Text="{x:Static language:i18n.areYouSureExit}" TextAlignment="Center" VerticalAlignment="Center" FontSize="26"/>
</ui:ContentDialog>


Expand Down
14 changes: 8 additions & 6 deletions elaphureLink.Wpf/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True}"
xmlns:language="clr-namespace:elaphureLink.Wpf.Properties.languages"
>
<UserControl DataContext="{Binding HomePageViewModel, Source={StaticResource ViewModelLocator}}">
<Grid Margin="10">
Expand All @@ -37,7 +38,8 @@
</MultiBinding>
</ui:ProgressBar.Visibility>
</ui:ProgressBar>
<TextBlock FontSize="48" FontFamily="Century Gothic" HorizontalAlignment="Center">elaphureLink</TextBlock>
<TextBlock FontSize="48" FontFamily="Century Gothic" HorizontalAlignment="Center" Text="{x:Static language:i18n.elaphureLink}"></TextBlock>
<TextBlock FontSize="16" FontFamily="Century Gothic" HorizontalAlignment="Center" Text="{x:Static language:i18n.keilWirelessProxy}"></TextBlock>
<Grid Margin="0,50,0,0">
<Grid.ColumnDefinitions>
<!-- 20% margin-left margin-right -->
Expand All @@ -51,7 +53,7 @@
VerticalAlignment="Center"
Orientation="Horizontal"
HorizontalAlignment="Left">
<TextBlock FontSize="16">Device Address</TextBlock>
<TextBlock FontSize="16" Text="{x:Static language:i18n.deviceIPAddress}"></TextBlock>
</StackPanel>
<StackPanel
Orientation="Horizontal"
Expand All @@ -64,7 +66,7 @@
VerticalAlignment="Center"
Orientation="Horizontal"
HorizontalAlignment="Left">
<TextBlock FontSize="16">Log Level</TextBlock>
<TextBlock FontSize="16" Text="{x:Static language:i18n.logLevel}"></TextBlock>
</StackPanel>
<StackPanel
Orientation="Horizontal"
Expand All @@ -83,20 +85,20 @@
VerticalAlignment="Center"
Orientation="Horizontal"
HorizontalAlignment="Left">
<TextBlock FontSize="16">Install Driver</TextBlock>
<TextBlock FontSize="16" Text="{x:Static language:i18n.installKeilDriver}"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button
IsEnabled="{Binding InstallDriverCommand.IsRunning, Converter={StaticResource BooleanInverseConverter}}"
Command="{Binding InstallDriverButtonCommand}">Install</Button>
Command="{Binding InstallDriverButtonCommand}" Content="{x:Static language:i18n.install}"></Button>
</StackPanel>
</Grid>
<Grid>
<StackPanel
VerticalAlignment="Center"
Orientation="Horizontal"
HorizontalAlignment="Left">
<TextBlock FontSize="16">Start Proxy</TextBlock>
<TextBlock FontSize="16" Text="{x:Static language:i18n.startProxy}"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<!-- Hide Toggle Switch with width 41 -->
Expand Down
15 changes: 8 additions & 7 deletions elaphureLink.Wpf/Pages/InfoPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
DataContext="{Binding InfoPageViewModel, Source={StaticResource ViewModelLocator}}"
Title="InfoPage">
Title="InfoPage"
xmlns:language="clr-namespace:elaphureLink.Wpf.Properties.languages"
>

<Grid Margin="12,10,10,10" d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True}">
<Grid.RowDefinitions>
Expand All @@ -24,16 +26,15 @@
<StackPanel
Orientation="Horizontal"
>
<TextBlock FontSize="14" Text="Version" VerticalAlignment="Center" Margin="0,0,5,0"/>
<TextBlock FontSize="14" Text="{x:Static language:i18n.version}" VerticalAlignment="Center" Margin="0,0,5,0"/>
<TextBlock FontWeight="Bold" FontSize="14" Text="{Binding GitVersionText}" VerticalAlignment="Center"/>
<Button Margin="20,0,0,0"
VerticalAlignment="Center"
IsEnabled="{Binding CheckUpdateButtonCommand.IsRunning, Converter={StaticResource BooleanInverseConverter}}"
Command="{Binding CheckUpdateButtonCommand}"
>Check Update</Button>
Command="{Binding CheckUpdateButtonCommand}" Content="{x:Static language:i18n.checkUpdate}"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="14" Text="Project Homepage" VerticalAlignment="Center" Margin="0,0,5,0"/>
<TextBlock FontSize="14" Text="{x:Static language:i18n.projectHomePage}" VerticalAlignment="Center" Margin="0,0,5,0"/>
<ui:HyperlinkButton Content="https://github.com/windowsair/elaphureLink" NavigateUri="https://github.com/windowsair/elaphureLink"/>
</StackPanel>
</StackPanel>
Expand All @@ -42,7 +43,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Contributor" FontSize="18"/>
<TextBlock Text="{x:Static language:i18n.contributor}" FontSize="18"/>
<ListView Grid.Row="1">
<ListView.Items>
<Label Content="windowsair"/>
Expand All @@ -54,7 +55,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Thirdparty Library" FontSize="18"/>
<TextBlock Text="{x:Static language:i18n.thridPartyLib}" FontSize="18"/>
<ListView Grid.Row="1">
<ListView.Items>
<Label Content="Autoupdater.NET"/>
Expand Down
24 changes: 11 additions & 13 deletions elaphureLink.Wpf/Pages/RootPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.modernwpf.com/2019"
mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="600"
Background="{DynamicResource SystemControlPageBackgroundAltHighBrush}">

Background="{DynamicResource SystemControlPageBackgroundAltHighBrush}"
xmlns:language="clr-namespace:elaphureLink.Wpf.Properties.languages"
>
<Grid>
<ui:NavigationView IsBackEnabled="False"
IsBackButtonVisible="Collapsed"
Expand All @@ -24,14 +25,13 @@
<MenuItem.Header>
<ui:PathIcon Width="16" Height="16" Style="{StaticResource svgTranslate}"/>
</MenuItem.Header>
<MenuItem Header="English" CommandParameter="en" Command=""/>
<MenuItem Header="简体中文" CommandParameter="zh-cn" Command=""/>
<MenuItem Header="English" Click="LanguageItem_Click" CommandParameter="en"/>
<MenuItem Header="简体中文" Click="LanguageItem_Click" CommandParameter="zh-cn"/>
<MenuItem Header="Français" Click="LanguageItem_Click" CommandParameter="fr-fr"/>
</MenuItem>
</Menu>
<!-- Align with NavigationViewItem -->
<TextBlock Margin="1,0,0,0" VerticalAlignment="Center">
Language
</TextBlock>
<TextBlock Margin="1,0,0,0" VerticalAlignment="Center" Text="{x:Static language:i18n.language}"></TextBlock>
</ui:SimpleStackPanel>

<ui:SimpleStackPanel Orientation="Horizontal">
Expand All @@ -43,22 +43,20 @@
</MenuItem>
</Menu>
<!-- Align with NavigationViewItem -->
<TextBlock Margin="1,0,0,0" VerticalAlignment="Center">
Theme
</TextBlock>
<TextBlock Margin="1,0,0,0" VerticalAlignment="Center" Text="{x:Static language:i18n.theme}"></TextBlock>
</ui:SimpleStackPanel>


</StackPanel>
</ui:NavigationView.PaneCustomContent>

<ui:NavigationView.MenuItems>
<ui:NavigationViewItem Content="Home" Tag="HomePage" IsSelected="True">
<ui:NavigationViewItem Content="{x:Static language:i18n.home}" Tag="HomePage" IsSelected="True">
<ui:NavigationViewItem.Icon>
<ui:PathIcon Style="{StaticResource svgHomeOutline}"/>
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Content="Log" Tag="LogPage" x:Name="RoomListPageNavigationViewItem">
<ui:NavigationViewItem Content="{x:Static language:i18n.log}" Tag="LogPage" x:Name="RoomListPageNavigationViewItem">
<ui:NavigationViewItem.Icon>
<ui:PathIcon Style="{StaticResource svgLog}"/>
</ui:NavigationViewItem.Icon>
Expand All @@ -76,7 +74,7 @@
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>

<ui:NavigationViewItem Content="Info" Tag="InfoPage">
<ui:NavigationViewItem Content="{x:Static language:i18n.about}" Tag="InfoPage">
<ui:NavigationViewItem.Icon>
<ui:PathIcon Style="{StaticResource svgInformationOutline}"/>
</ui:NavigationViewItem.Icon>
Expand Down
30 changes: 30 additions & 0 deletions elaphureLink.Wpf/Pages/RootPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using ModernWpf;
using ModernWpf.Controls;
using ModernWpf.Media.Animation;
using System.Threading;
using System.Globalization;

namespace elaphureLink.Wpf.Pages
{
Expand Down Expand Up @@ -91,5 +93,33 @@ NavigationViewSelectionChangedEventArgs args
this.MainFrame.Navigate(pageType, null, this.transitionInfo);
}
}

private void LanguageItem_Click(object sender, RoutedEventArgs e)
{
// Cast the sender as a MenuItem
if (sender is MenuItem item)
{
// Retrieve the CommandParameter
var language = item.CommandParameter as string;

// Handle the selected language
switch (language)
{
case "fr-fr":
case "zh-cn":
// Handle language selected
Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
break;
default:
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
break;
}

// Refresh the main window (or any other windows)
Application.Current.MainWindow.Content = new RootPage();
}
}
}
}
70 changes: 0 additions & 70 deletions elaphureLink.Wpf/Properties/Resources.Designer.cs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ci build fail:

CSC : error CS2001: Source file 'D:\a\elaphureLink\elaphureLink\elaphureLink.Wpf\Properties\Resources.Designer.cs' could not be found. 

Should we delete this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it looks like these are modifications to the source files. Do you need to submit the changes to csproj along with them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files were empty(Resources.resx/Resources.resx.cs), I might delete them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it looks like these are modifications to the source files. Do you need to submit the changes to csproj along with them?

Oups, I didn't submit changes to .csproj, I'm beginner to C# and WPF, should I submit the .csproj file along with the commit ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it looks like these are modifications to the source files. Do you need to submit the changes to csproj along with them?

Oups, I didn't submit changes to .csproj, I'm beginner to C# and WPF, should I submit the .csproj file along with the commit ?

Yes. You can submit the changes to related files such as .csproj on the basis of this patch.

This file was deleted.

Loading
Loading