Skip to content

Commit

Permalink
Add multi-language support 添加多语言支持以及中文翻译 (BestOwl#18)
Browse files Browse the repository at this point in the history
* 添加多语言支持以及中文翻译

* 添加任务栏图标菜单多语言支持
  • Loading branch information
skirky3605 authored Dec 22, 2022
1 parent 6a95be7 commit dbd0ede
Show file tree
Hide file tree
Showing 17 changed files with 727 additions and 59 deletions.
5 changes: 3 additions & 2 deletions MyPhone/Controls/BluetoothDeviceListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Searching nearby Bluetooth devices..." />
<TextBlock x:Uid="BluetoothDeviceList_SearchingTip" Text="Searching nearby Bluetooth devices..." />
<ProgressBar IsIndeterminate="True" Grid.Row="1"/>

<ListView ItemsSource="{x:Bind ViewModel.Devices, Mode=OneWay}"
Expand Down Expand Up @@ -45,7 +45,8 @@
Margin="12,6,0,6"
Style="{StaticResource SubtitleTextBlockStyle}"/>

<TextBlock Text="Paired"
<TextBlock x:Uid="BluetoothDeviceList_Paired"
Text="Paired"
Visibility="{x:Bind IsPaired}"
VerticalAlignment="Center"
Foreground="{ThemeResource ToolTipForegroundThemeBrush}"
Expand Down
6 changes: 5 additions & 1 deletion MyPhone/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

<Grid.Resources>
<XamlUICommand
x:Uid="Taskbar_Menu_OpenApp"
x:Key="OpenAppCommand"
ExecuteRequested="OpenAppCommand_ExecuteRequested"
Label="Open My Phone"
Description="Open My Phone" />
<XamlUICommand
x:Uid="Taskbar_Menu_Exit"
x:Key="ExitCommand"
ExecuteRequested="ExitCommand_ExecuteRequested"
Label="Exit"
Expand All @@ -44,7 +46,8 @@
Source="Assets/Square44x44Logo.png"
Width="16"
Height="16"/>
<TextBlock x:Name="AppTitle"
<TextBlock x:Uid="AppTitleText"
x:Name="AppTitle"
Text="{x:Bind local:MainWindow.AppTitleDisplayName}"
VerticalAlignment="Center"
Margin="12,0,0,0"
Expand All @@ -56,6 +59,7 @@
Canvas.ZIndex="0"/>

<tb:TaskbarIcon
x:Uid="TaskBarIcon"
ToolTipText="{x:Bind local:MainWindow.AppTitleDisplayName}"
IconSource="/Assets/Icon.ico"
MenuActivation="LeftOrRightClick"
Expand Down
3 changes: 2 additions & 1 deletion MyPhone/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.UI.Xaml.Media;
using System;
using System.Diagnostics;
using Windows.ApplicationModel.Resources;
using Windows.Win32;
using WinRT;

Expand All @@ -26,7 +27,7 @@ public sealed partial class MainWindow : Window, IDisposable
{
public static XamlRoot XamlRoot { get => _instance.windowRoot.XamlRoot; }
public static DispatcherQueue WindowDispatcher { get => _instance.DispatcherQueue; }
public static string AppTitleDisplayName { get => Windows.ApplicationModel.Package.Current.DisplayName; }
public static string AppTitleDisplayName { get => ResourceLoader.GetForViewIndependentUse("Resources").GetString("AppDisplayName"); }

private readonly ISettingsService _settingsService;

Expand Down
14 changes: 8 additions & 6 deletions MyPhone/Models/ContactViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.Resources;
using Windows.Graphics.Imaging;

namespace GoodTimeStudio.MyPhone.Models
Expand All @@ -33,19 +34,20 @@ public ContactViewModel(Contact contact, ILogger<ContactViewModel> logger)
_logger = logger;
Contact = contact;
Info = new ObservableCollection<ContactDetialInformation>();
ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse("Resources");

if (contact.Detail.Telephones != null)
{
foreach (var phone in contact.Detail.Telephones)
{
Info.Add(new ContactDetialInformation(
"\uE717", phone.Number,
$"Phone ({phone.Type})",
resourceLoader.GetString("Contact_Phone"),
primaryAction: Call,
primaryActionTooltip: $"Call {phone.Number}",
primaryActionTooltip: resourceLoader.GetString("Contact_Call") + phone.Number,
secondaryAction: (i) => { /* TODO: Navigate to message page */ },
secondaryActionIcon: "\uE8BD",
secondaryActionTooltip: $"Send message to {phone.Number}"));
secondaryActionTooltip: resourceLoader.GetString("Contact_SendMessage") + phone.Number));
}
}

Expand All @@ -55,22 +57,22 @@ public ContactViewModel(Contact contact, ILogger<ContactViewModel> logger)
{
Info.Add(new ContactDetialInformation(
"\uE715", email.EmailAddress,
"Email"));
resourceLoader.GetString("Contact_Email")));
}
}

if (!string.IsNullOrWhiteSpace(contact.Detail.Organization))
{
Info.Add(new ContactDetialInformation(
"\uE821", contact.Detail.Organization,
"Organization"));
resourceLoader.GetString("Contact_Phone")));
}

if (!string.IsNullOrWhiteSpace(contact.Detail.OrganizationalUnit))
{
Info.Add(new ContactDetialInformation(
"\uE821", contact.Detail.OrganizationalUnit,
"Organizational Unit"));
resourceLoader.GetString("Contact_Organizational_Unit")));
}

_ = LoadPhotoAsync();
Expand Down
94 changes: 94 additions & 0 deletions MyPhone/MultilingualResources/MyPhone.qps-ploc.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en-US" target-language="qps-ploc" original="MYPHONE/STRINGS/EN-US/RESOURCES.RESW" tool-id="MultilingualAppToolkit" product-name="n/a" product-version="n/a" build-num="n/a">
<header>
<tool tool-id="MultilingualAppToolkit" tool-name="Multilingual App Toolkit" tool-version="1.0.0.0" tool-company="Microsoft" />
</header>
<body>
<group id="MYPHONE/STRINGS/EN-US/RESOURCES.RESW" datatype="resx">
<trans-unit id="AppDisplayName" translate="yes" xml:space="preserve">
<source>My Phone Assistant</source>
<target state="new">My Phone Assistant</target>
</trans-unit>
<trans-unit id="AppTitleText.Text" translate="yes" xml:space="preserve">
<source>My Phone Assistant</source>
<target state="new">My Phone Assistant</target>
</trans-unit>
<trans-unit id="Failed_Connect_Error_Front" translate="yes" xml:space="preserve">
<source>Failed to pair "</source>
<target state="new">Failed to pair "</target>
</trans-unit>
<trans-unit id="Failed_Connect_Error_Second" translate="yes" xml:space="preserve">
<source>". Reason:</source>
<target state="new">". Reason:</target>
</trans-unit>
<trans-unit id="Item_Call" translate="yes" xml:space="preserve">
<source>Call</source>
<target state="new">Call</target>
</trans-unit>
<trans-unit id="Item_Contacts" translate="yes" xml:space="preserve">
<source>Contacts</source>
<target state="new">Contacts</target>
</trans-unit>
<trans-unit id="Item_Debug" translate="yes" xml:space="preserve">
<source>Debug</source>
<target state="new">Debug</target>
</trans-unit>
<trans-unit id="Item_Message" translate="yes" xml:space="preserve">
<source>Message</source>
<target state="new">Message</target>
</trans-unit>
<trans-unit id="Item_Settings" translate="yes" xml:space="preserve">
<source>Settings</source>
<target state="new">Settings</target>
</trans-unit>
<trans-unit id="MenuItem_Call" translate="yes" xml:space="preserve">
<source>Call</source>
<target state="new">Call</target>
</trans-unit>
<trans-unit id="MenuItem_Contacts" translate="yes" xml:space="preserve">
<source>Contacts</source>
<target state="new">Contacts</target>
</trans-unit>
<trans-unit id="MenuItem_Debug" translate="yes" xml:space="preserve">
<source>Debug</source>
<target state="new">Debug</target>
</trans-unit>
<trans-unit id="MenuItem_Message" translate="yes" xml:space="preserve">
<source>Message</source>
<target state="new">Message</target>
</trans-unit>
<trans-unit id="MenuItem_Settings" translate="yes" xml:space="preserve">
<source>Settings</source>
<target state="new">Settings</target>
</trans-unit>
<trans-unit id="Oobe_Connect.Text" translate="yes" xml:space="preserve">
<source>Connect</source>
<target state="new">Connect</target>
</trans-unit>
<trans-unit id="Oobe_Describe.Text" translate="yes" xml:space="preserve">
<source>Make phone calls and send/receive SMS on your PC</source>
<target state="new">Make phone calls and send/receive SMS on your PC</target>
</trans-unit>
<trans-unit id="Oobe_Tip.Text" translate="yes" xml:space="preserve">
<source>Before we get started, we need to connect to your phone</source>
<target state="new">Before we get started, we need to connect to your phone</target>
</trans-unit>
<trans-unit id="Oobe_Welcome.Text" translate="yes" xml:space="preserve">
<source>Welcome to
My Phone Assistant</source>
<target state="new">Welcome to
My Phone Assistant</target>
</trans-unit>
<trans-unit id="Permission_Error" translate="yes" xml:space="preserve">
<source>Sorry, but we do not have the permission to connect your phone.</source>
<target state="new">Sorry, but we do not have the permission to connect your phone.</target>
</trans-unit>
<trans-unit id="TaskBarIcon.ToolTipText" translate="yes" xml:space="preserve">
<source>My Phone Assistant</source>
<target state="new">My Phone Assistant</target>
</trans-unit>
</group>
</body>
</file>
</xliff>
10 changes: 6 additions & 4 deletions MyPhone/MyPhone.csproj
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
Expand Down Expand Up @@ -38,9 +39,9 @@
<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="Controls\DevicePairDialog.xaml" />
<None Remove="MultilingualResources\MyPhone.qps-ploc.xlf" />
<None Remove="Pages\ContactsPage.xaml" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.json" />
<Content Include="Assets\SplashScreen.scale-200.png" />
Expand All @@ -50,7 +51,6 @@
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
<PackageReference Include="CommunityToolkit.WinUI" Version="7.1.2" />
Expand All @@ -73,7 +73,6 @@
<PackageReference Include="Shiny.Logging.AppCenter" Version="2.5.5" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<!-- Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored -->
Expand All @@ -86,6 +85,9 @@
<ItemGroup>
<Resource Include="appsettings.json" />
</ItemGroup>
<ItemGroup>
<XliffResource Include="MultilingualResources\MyPhone.qps-ploc.xlf" />
</ItemGroup>
<ItemGroup>
<Page Update="Pages\ContactsPage.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -114,4 +116,4 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>
</Project>
5 changes: 3 additions & 2 deletions MyPhone/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
</Dependencies>

<Resources>
<Resource Language="x-generate"/>
<Resource Language="en-US"/>
<Resource Language="zh-CN"/>
</Resources>

<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="My Phone Assistant"
DisplayName="ms-resource:AppDisplayName"
Description="MyPhone"
BackgroundColor="transparent"
Square150x150Logo="Assets\Square150x150Logo.png"
Expand Down
1 change: 1 addition & 0 deletions MyPhone/Pages/ContactsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<Grid>
<controls:ListDetailsView
x:Uid="Contacts_List"
BackButtonBehavior="Automatic"
NoSelectionContent="Select an item to view"
CompactModeThresholdWidth="720"
Expand Down
Loading

0 comments on commit dbd0ede

Please sign in to comment.