Skip to content

Commit

Permalink
feat: Add i18n for WinUI
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Nov 22, 2023
1 parent 105168d commit f65de92
Show file tree
Hide file tree
Showing 19 changed files with 511 additions and 105 deletions.
43 changes: 42 additions & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,29 @@ jobs:

- name: Build
shell: pwsh
run: .\build.ps1
run: |
.\build.ps1
.\build.WinUI.ps1 x64
.\build.WinUI.ps1 arm64
- name: Upload
uses: actions/upload-artifact@v3
with:
name: ${{ env.ProjectName }}
path: ${{ env.ProjectName }}\bin\${{ env.Configuration }}\${{ env.NET_TFM }}\generic\publish\

- name: Upload WinUI x64
uses: actions/upload-artifact@v3
with:
name: ${{ env.ProjectName }}.WinUI.x64
path: ${{ env.ProjectName }}.WinUI\bin\x64\${{ env.Configuration }}\${{ env.NET_TFM }}\win-x64\publish\

- name: Upload WinUI arm64
uses: actions/upload-artifact@v3
with:
name: ${{ env.ProjectName }}.WinUI.arm64
path: ${{ env.ProjectName }}.WinUI\bin\arm64\${{ env.Configuration }}\${{ env.NET_TFM }}\win-arm64\publish\

nuget:
needs: [test, check_format]
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
Expand Down Expand Up @@ -102,6 +117,16 @@ jobs:
name: ${{ env.ProjectName }}
path: ${{ env.ProjectName }}

- uses: actions/download-artifact@v3
with:
name: ${{ env.ProjectName }}.WinUI.x64
path: ${{ env.ProjectName }}.WinUI.x64

- uses: actions/download-artifact@v3
with:
name: ${{ env.ProjectName }}.WinUI.arm64
path: ${{ env.ProjectName }}.WinUI.arm64

- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1
Expand All @@ -114,6 +139,20 @@ jobs:
7z a -mx9 "$zip_path" ${{ env.ProjectName }}
echo "GENERIC_SHA256=$((Get-FileHash $zip_path -Algorithm SHA256).Hash)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Package WinUI x64
shell: pwsh
run: |
$zip_path = "builtfiles/$env:ProjectName-${{ steps.tag.outputs.tag }}-x64.7z"
7z a -mx9 "$zip_path" ${{ env.ProjectName }}.WinUI.x64
echo "X64_SHA256=$((Get-FileHash $zip_path -Algorithm SHA256).Hash)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Package WinUI arm64
shell: pwsh
run: |
$zip_path = "builtfiles/$env:ProjectName-${{ steps.tag.outputs.tag }}-arm64.7z"
7z a -mx9 "$zip_path" ${{ env.ProjectName }}.WinUI.arm64
echo "ARM64_SHA256=$((Get-FileHash $zip_path -Algorithm SHA256).Hash)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Create a new GitHub release
uses: ncipollo/release-action@v1
with:
Expand All @@ -126,3 +165,5 @@ jobs:
| Filename | SHA-256 |
| :- | :- |
| <sub>${{ env.ProjectName }}-${{ steps.tag.outputs.tag }}.7z</sub> | <sub>${{ env.GENERIC_SHA256 }}</sub> |
| <sub>${{ env.ProjectName }}-${{ steps.tag.outputs.tag }}-x64.7z</sub> | <sub>${{ env.X64_SHA256 }}</sub> |
| <sub>${{ env.ProjectName }}-${{ steps.tag.outputs.tag }}-arm64.7z</sub> | <sub>${{ env.ARM64_SHA256 }}</sub> |
12 changes: 10 additions & 2 deletions NatTypeTester.WinUI/Extensions/ContentDialogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ internal static class ContentDialogExtensions
{
public static async ValueTask HandleExceptionWithContentDialogAsync(this Exception ex, XamlRoot root)
{
ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse();
ContentDialog dialog = new();
try
{
dialog.XamlRoot = root;
dialog.Title = nameof(NatTypeTester);
dialog.Content = ex.Message;
dialog.PrimaryButtonText = @"OK";

string content = resourceLoader.GetString(ex.Message);
if (string.IsNullOrEmpty(content))
{
content = ex.Message;
}
dialog.Content = content;

dialog.PrimaryButtonText = resourceLoader.GetString(@"OK");

await dialog.ShowAsync();
}
Expand Down
2 changes: 1 addition & 1 deletion NatTypeTester.WinUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public MainWindow()
Title = nameof(NatTypeTester);
ExtendsContentIntoTitleBar = true;

AppWindow.Resize(new SizeInt32(500, 590));
AppWindow.Resize(new SizeInt32(500, 560));
AppWindow.SetIcon(@"Assets\icon.ico");

// CenterScreen
Expand Down
1 change: 1 addition & 0 deletions NatTypeTester.WinUI/NatTypeTesterModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
global using Volo.Abp.Autofac;
global using Volo.Abp.DependencyInjection;
global using Volo.Abp.Modularity;
global using Windows.ApplicationModel.Resources;
global using Windows.Graphics;
global using Windows.System;

Expand Down
177 changes: 177 additions & 0 deletions NatTypeTester.WinUI/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BindingTestTextBox.Header" xml:space="preserve">
<value>Binding test</value>
</data>
<data name="FilteringBehaviorTextBox.Header" xml:space="preserve">
<value>Filtering behavior</value>
</data>
<data name="LocalEndComboBox.Header" xml:space="preserve">
<value>Local end</value>
</data>
<data name="LocalEndComboBox.PlaceholderText" xml:space="preserve">
<value>Any</value>
</data>
<data name="MappingBehaviorTextBox.Header" xml:space="preserve">
<value>Mapping behavior</value>
</data>
<data name="NoProxy.Content" xml:space="preserve">
<value>Don't use Proxy</value>
</data>
<data name="OK" xml:space="preserve">
<value>OK</value>
</data>
<data name="ProxyPasswordTextBox.Header" xml:space="preserve">
<value>Password</value>
</data>
<data name="ProxyRadioButtons.Header" xml:space="preserve">
<value>Proxy</value>
</data>
<data name="ProxyServerTextBox.Header" xml:space="preserve">
<value>Server</value>
</data>
<data name="ProxyUsernameTextBox.Header" xml:space="preserve">
<value>Username</value>
</data>
<data name="PublicEndTextBox.Header" xml:space="preserve">
<value>Public end</value>
</data>
<data name="RFC3489NatTypeTextBox.Header" xml:space="preserve">
<value>NAT type</value>
</data>
<data name="RFC3489Warning.Message" xml:space="preserve">
<value>This protocol is obsoleted and may not be suitable for modern routers or NAT.</value>
</data>
<data name="ServersComboBox.Header" xml:space="preserve">
<value>STUN Server</value>
</data>
<data name="SOCKS5Proxy.Content" xml:space="preserve">
<value>SOCKS5</value>
</data>
<data name="TestButton.Content" xml:space="preserve">
<value>Test</value>
</data>
<data name="Unknown proxy address" xml:space="preserve">
<value>Unknown proxy address</value>
</data>
<data name="Wrong STUN Server!" xml:space="preserve">
<value>Wrong STUN Server!</value>
</data>
</root>
Loading

0 comments on commit f65de92

Please sign in to comment.