Skip to content

Commit

Permalink
[Feat] Localization Test Passed
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed Sep 30, 2023
1 parent b057215 commit 95abf5a
Show file tree
Hide file tree
Showing 21 changed files with 506 additions and 37 deletions.
4 changes: 3 additions & 1 deletion PipManager/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
x:Class="PipManager.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:languages="clr-namespace:PipManager.Languages"

Check warning on line 9 in PipManager/App.xaml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant namespace alias

Namespace alias 'languages' is not required by code and can be safely removed
xmlns:pipManager="clr-namespace:PipManager">

Check warning on line 10 in PipManager/App.xaml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant namespace alias

Namespace alias 'pipManager' is not required by code and can be safely removed
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
8 changes: 8 additions & 0 deletions PipManager/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Reflection;

Check warning on line 10 in PipManager/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using System.Windows.Threading;
using PipManager.Languages;
using PipManager.Services.Configuration;
using PipManager.Views.Pages.About;
using PipManager.Views.Pages.Library;
Expand All @@ -18,6 +19,7 @@
using LibraryViewModel = PipManager.ViewModels.Pages.Library.LibraryViewModel;
using SearchViewModel = PipManager.ViewModels.Pages.Search.SearchViewModel;
using SettingsViewModel = PipManager.ViewModels.Pages.Settings.SettingsViewModel;
using System.Globalization;

namespace PipManager;

Expand Down Expand Up @@ -71,6 +73,12 @@ public static T GetService<T>()
/// </summary>
private void OnStartup(object sender, StartupEventArgs e)
{
var language = GetLanguage.FromFile(Path.Combine(Directory.GetCurrentDirectory(), "config.json"));
if (language != null)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
}
Host.Start();
}

Expand Down
21 changes: 21 additions & 0 deletions PipManager/Languages/GetLanguage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.IO;
using Newtonsoft.Json;
using PipManager.Models;

namespace PipManager.Languages;

public static class GetLanguage
{
public static readonly Dictionary<string, string> LanguageList = new()
{
{"English", "en-US"},
{"简体中文", "zh-CN"}
};

public static string? FromFile(string path)
{
var language= JsonConvert.DeserializeObject<AppConfig>(File.ReadAllText(path)).Personalization.Language;

Check warning on line 17 in PipManager/Languages/GetLanguage.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Dereference of a possibly null reference.

Dereference of a possibly null reference
return language != "Auto" ? language : null;
}

}
108 changes: 108 additions & 0 deletions PipManager/Languages/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 135 additions & 0 deletions PipManager/Languages/Lang.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?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="MainWindowNavigationContentAbout" xml:space="preserve">
<value>About</value>
</data>
<data name="MainWindowNavigationContentLibrary" xml:space="preserve">
<value>Library</value>
</data>
<data name="MainWindowNavigationContentSearch" xml:space="preserve">
<value>Search</value>
</data>
<data name="MainWindowNavigationContentSettings" xml:space="preserve">
<value>Settings</value>
</data>
<data name="SettingsCategoryPersonalization" xml:space="preserve">
<value>Personalization</value>
</data>
</root>
Loading

0 comments on commit 95abf5a

Please sign in to comment.