2
0

Add project files.

This commit is contained in:
DangHome
2022-05-23 00:58:58 +08:00
parent e5a279a1fd
commit f0b02be1a5
51 changed files with 3090 additions and 0 deletions

115
Language/CulturesHelper.cs Normal file
View File

@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
namespace CMM.Language
{
public class CulturesHelper
{
private bool _isFoundInstalledCultures = false;
const string LanguageFolder = "/Language;component";
const string ResourceLocalPath = "pack://application:,," + LanguageFolder;
const string LanguageFileName = "StringResources";
public List<CultureInfo> SupportedCultures { get; private set; } = new List<CultureInfo>();
public CulturesHelper() => Init();
private void Init()
{
if (!_isFoundInstalledCultures)
{
var cultureInfo = new CultureInfo("");
var Languages = GetAllLanguageResource();
GetAllLanguageResource().ForEach(file =>
{
try
{
string cultureName = file.Substring(file.IndexOf(".") + 1).Replace(".xaml", "");
cultureInfo = CultureInfo.GetCultureInfo(cultureName);
if (cultureInfo != null)
{
SupportedCultures.Add(cultureInfo);
}
}
catch (ArgumentException) { }
});
_isFoundInstalledCultures = true;
}
}
/// <summary>
/// 增加Language的XMAL檔
/// </summary>
private static List<string> GetAllLanguageResource()
{
var Languages = new List<string>();
string uriPath = ResourceLocalPath + "/" + LanguageFileName;
Languages.Add(uriPath + ".en-US.xaml");
Languages.Add(uriPath + ".zh-TW.xaml");
return Languages;
}
public void ChangeCulture(string cultureName)
{
var cultureInfo = CultureInfo.GetCultureInfo(cultureName);
if (cultureInfo != null)
{
ChangeCulture(cultureInfo);
}
}
/// <summary>
/// 切換語系
/// </summary>
public void ChangeCulture(CultureInfo culture)
{
if (SupportedCultures.Contains(culture))
{
var existsRD = Application.Current.Resources.MergedDictionaries
.Where(x => x.Source.OriginalString.StartsWith(ResourceLocalPath, StringComparison.CurrentCultureIgnoreCase) ||
x.Source.OriginalString.StartsWith(LanguageFolder, StringComparison.CurrentCultureIgnoreCase))
.FirstOrDefault();
if (existsRD == null) return;
var resourceFile = $"{ResourceLocalPath}/{LanguageFileName}.{culture.Name}.xaml";
var res = new ResourceDictionary()
{
Source = new Uri(resourceFile, UriKind.Absolute)
};
Application.Current.Resources.MergedDictionaries.Remove(existsRD);
Application.Current.Resources.MergedDictionaries.Add(res);
}
}
}
public static class Lang
{
public static string Find(string key)
{
if (Application.Current == null) return null;
try
{
return (string)Application.Current.FindResource(key);
}
catch
{
return string.Empty;
}
}
}
}

35
Language/Language.csproj Normal file
View File

@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<RootNamespace>CMM.Language</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<Product>ControlMyMonitorManagement</Product>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Major>1</Major>
<Minor>0</Minor>
<ProjectStartedDate>$([System.DateTime]::op_Subtraction($([System.DateTime]::get_Now().get_Date()),$([System.DateTime]::new(2017,9,17))).get_TotalDays())</ProjectStartedDate>
<DaysSinceProjectStarted>$([System.DateTime]::Now.ToString(Hmm))</DaysSinceProjectStarted>
<DateTimeSuffix>$([System.DateTime]::Now.ToString(yyyyMMdd))</DateTimeSuffix>
<VersionSuffix>$(Major).$(Minor).$(ProjectStartedDate).$(DaysSinceProjectStarted)</VersionSuffix>
<AssemblyVersion Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</AssemblyVersion>
<AssemblyVersion Condition=" '$(DateTimeSuffix)' != '' ">$(VersionSuffix)</AssemblyVersion>
<Version Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</Version>
<Version Condition=" '$(DateTimeSuffix)' != '' ">$(DateTimeSuffix)</Version>
</PropertyGroup>
<ItemGroup>
<None Update="StringResources.en-US.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
<None Update="StringResources.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
<None Update="StringResources.zh-TW.xam">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
</ResourceDictionary>

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
</ResourceDictionary>

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
</ResourceDictionary>