Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
c1f8800f
Commit
c1f8800f
authored
Dec 26, 2024
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 Misc添加Culture ,支持lang文件夹内的多国语言包。
parent
9eca2e65
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
212 additions
and
12 deletions
+212
-12
Culture.cs
Project.FLY.Misc/MISC/Culture.cs
+195
-0
Misc.csproj
Project.FLY.Misc/MISC/Misc.csproj
+3
-0
UcSectionLanguage.xaml.cs
...FLY.Thick.Base.UI/CustomSection/UcSectionLanguage.xaml.cs
+11
-10
FLY.Thick.Base.UI.csproj
...FLY.Thick.Base/FLY.Thick.Base.UI/FLY.Thick.Base.UI.csproj
+0
-1
StringResource.PgBorderSearch.xaml
...mes/StringResources/en/StringResource.PgBorderSearch.xaml
+1
-0
StringResource.PgCustomSections.xaml
...s/StringResources/en/StringResource.PgCustomSections.xaml
+2
-1
No files found.
Project.FLY.
Thick.Base/FLY.Thick.Base.UI
/Culture.cs
→
Project.FLY.
Misc/MISC
/Culture.cs
View file @
c1f8800f
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.IO
;
using
System.Reflection
;
using
System.Windows
;
namespace
FLY.Thick.Base.UI
namespace
Misc
{
public
class
Culture
:
INotifyPropertyChanged
{
...
...
@@ -12,60 +14,126 @@ namespace FLY.Thick.Base.UI
public
string
Language
{
get
;
set
;
}
=
"zh"
;
public
string
filePath
=
"culture.json"
;
string
fileFullPath
=
"culture.json"
;
string
dirPath
;
public
List
<
string
>
langs
{
get
;
}
=
new
List
<
string
>();
static
Dictionary
<
string
,
string
>
langInfos
;
static
Culture
()
{
langInfos
=
new
Dictionary
<
string
,
string
>
{
{
"ch"
,
"中文"
},
{
"en"
,
"English"
},
{
"ru"
,
"русский язык"
},
{
"fr"
,
"français"
},
{
"de"
,
"dé yǔ"
},
{
"ja"
,
"日本語"
},
{
"ko"
,
"한국어"
}
};
}
public
static
string
GetLangInfo
(
string
lang
)
{
if
(
langInfos
.
ContainsKey
(
lang
))
{
return
langInfos
[
lang
];
}
else
{
return
lang
;
}
}
public
static
LanguageInfo
GetLanguageInfo
(
string
lang
)
{
return
new
LanguageInfo
()
{
Info
=
Culture
.
GetLangInfo
(
lang
),
Language
=
lang
};
}
public
bool
Save
()
{
string
fileFullPath
=
Path
.
Combine
(
dirPath
,
filePath
);
return
CultureJsonDb
.
Save
(
fileFullPath
,
this
);
}
public
bool
Load
()
{
//记录加载时的路径。 就算用 System.Environment.CurrentDirectory = rootDir; 改变后, 也能保存回加载时的位置
string
p
ath
=
System
.
IO
.
Directory
.
GetCurrentDirectory
();
dirP
ath
=
System
.
IO
.
Directory
.
GetCurrentDirectory
();
fileFullPath
=
Path
.
Combine
(
p
ath
,
filePath
);
string
fileFullPath
=
Path
.
Combine
(
dirP
ath
,
filePath
);
return
CultureJsonDb
.
Load
(
fileFullPath
,
this
);
}
void
GetOtherLang
()
{
langs
.
Clear
();
langs
.
Add
(
"ch"
);
langs
.
Add
(
"en"
);
//添加其它语言包
string
langPath
=
Path
.
Combine
(
dirPath
,
"lang"
);
if
(!
Directory
.
Exists
(
langPath
))
return
;
DirectoryInfo
directory
=
new
DirectoryInfo
(
langPath
);
var
dirs
=
directory
.
GetDirectories
();
foreach
(
var
dir
in
dirs
)
{
string
xamlFilePath
=
Path
.
Combine
(
dir
.
FullName
,
"StringResource.xaml"
);
if
(
File
.
Exists
(
xamlFilePath
))
{
langs
.
Add
(
dir
.
Name
);
}
}
}
public
void
LoadCulture
(
Type
appType
)
{
Assembly
asm
=
Assembly
.
GetAssembly
(
appType
);
string
assemblyName
=
asm
.
GetName
().
Name
;
GetOtherLang
();
string
language
=
Language
;
if
(
language
==
"zh"
)
return
;
//List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
//foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
//{
// dictionaryList.Add(dictionary);
//}
string
requestedCulture
=
$@"pack://application:,,,/
{
assemblyName
}
;component/Themes/StringResources/
{
language
}
/StringResource.xaml"
;
ResourceDictionary
resourceDictionary
;
try
//程序集的,只支持 zh,en. 其它都是 lang 文件夹 内的
ResourceDictionary
resourceDictionary
=
null
;
if
(
language
==
"en"
)
{
resourceDictionary
=
new
ResourceDictionary
()
{
Source
=
new
Uri
(
requestedCulture
)
};
string
uriString
=
$@"pack://application:,,,/
{
assemblyName
}
;component/Themes/StringResources/
{
language
}
/StringResource.xaml"
;
try
{
resourceDictionary
=
new
ResourceDictionary
()
{
Source
=
new
Uri
(
uriString
)
};
}
catch
{
return
;
}
}
catch
else
{
return
;
string
uriString
=
Path
.
Combine
(
dirPath
,
"lang"
,
language
,
"StringResource.xaml"
);
try
{
using
(
FileStream
fs
=
new
FileStream
(
uriString
,
FileMode
.
Open
,
FileAccess
.
Read
))
{
resourceDictionary
=
(
ResourceDictionary
)
System
.
Windows
.
Markup
.
XamlReader
.
Load
(
fs
);
}
}
catch
{
return
;
}
}
//if(resourceDictionary == null)
//{
// requestedCulture = @"Resources\StringResource.xaml";
// resourceDictionary = dictionaryList.FirstOrDefault(d =< d.Source.OriginalString.Equals(requestedCulture));
//}
if
(
resourceDictionary
!=
null
)
{
//Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
Application
.
Current
.
Resources
.
MergedDictionaries
.
Add
(
resourceDictionary
);
}
}
...
...
@@ -116,4 +184,12 @@ namespace FLY.Thick.Base.UI
}
public
string
Language
{
get
;
set
;
}
=
"zh"
;
}
public
class
LanguageInfo
:
INotifyPropertyChanged
{
public
string
Language
{
get
;
set
;
}
public
string
Info
{
get
;
set
;
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
}
}
Project.FLY.Misc/MISC/Misc.csproj
View file @
c1f8800f
...
...
@@ -64,6 +64,7 @@
</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"PresentationFramework"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
...
...
@@ -71,6 +72,7 @@
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Drawing"
/>
<Reference
Include=
"System.Windows.Forms"
/>
<Reference
Include=
"System.Xaml"
/>
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"WindowsBase"
/>
...
...
@@ -80,6 +82,7 @@
<Compile
Include=
"common.cs"
/>
<Compile
Include=
"Conventer.cs"
/>
<Compile
Include=
"CRC.cs"
/>
<Compile
Include=
"Culture.cs"
/>
<Compile
Include=
"DATARANGE.cs"
/>
<Compile
Include=
"Enumerable.cs"
/>
<Compile
Include=
"IgnoreAttribute.cs"
/>
...
...
Project.FLY.Thick.Base/FLY.Thick.Base.UI/CustomSection/UcSectionLanguage.xaml.cs
View file @
c1f8800f
using
CommunityToolkit.Mvvm.Input
;
using
FLY.AppHelper
;
using
Misc
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.ComponentModel
;
using
System.Linq
;
...
...
@@ -39,17 +40,24 @@ namespace FLY.Thick.Base.UI.CustomSection
public
RelayCommand
OkCmd
{
get
;
private
set
;
}
Culture
culture
;
public
UcSectionLanguageVm
()
{
OkCmd
=
new
RelayCommand
(
Ok
);
LanguageList
.
Add
(
new
LanguageInfo
()
{
Info
=
"中文"
,
Language
=
"ch"
});
LanguageList
.
Add
(
new
LanguageInfo
()
{
Info
=
"English"
,
Language
=
"en"
});
}
public
void
Init
(
Culture
culture
)
{
this
.
culture
=
culture
;
foreach
(
var
lang
in
culture
.
langs
)
{
LanguageList
.
Add
(
Culture
.
GetLanguageInfo
(
lang
));
}
try
{
CurrentLanguage
=
LanguageList
.
First
(
l
=>
l
.
Language
==
culture
.
Language
);
...
...
@@ -59,6 +67,7 @@ namespace FLY.Thick.Base.UI.CustomSection
CurrentLanguage
=
LanguageList
[
0
];
}
}
private
void
Ok
()
{
string
msg
=
(
string
)
Application
.
Current
.
FindResource
(
"str.PgCustomSections.IsSureToReboot"
);
...
...
@@ -77,12 +86,4 @@ namespace FLY.Thick.Base.UI.CustomSection
AppJustOne
.
Restart
();
}
}
public
class
LanguageInfo
:
INotifyPropertyChanged
{
public
string
Language
{
get
;
set
;
}
public
string
Info
{
get
;
set
;
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
}
}
Project.FLY.Thick.Base/FLY.Thick.Base.UI/FLY.Thick.Base.UI.csproj
View file @
c1f8800f
...
...
@@ -96,7 +96,6 @@
<Compile
Include=
"CtMicroGage.xaml.cs"
>
<DependentUpon>
CtMicroGage.xaml
</DependentUpon>
</Compile>
<Compile
Include=
"Culture.cs"
/>
<Compile
Include=
"CustomMenu\AdrMenu.cs"
/>
<Compile
Include=
"CustomMenu\CustomMenu.cs"
/>
<Compile
Include=
"CustomMenu\UpdateMenu.cs"
/>
...
...
Project.FLY.Thick.Base/FLY.Thick.Base.UI/Themes/StringResources/en/StringResource.PgBorderSearch.xaml
View file @
c1f8800f
...
...
@@ -25,6 +25,7 @@
<system:String x:Key="str.PgBorderSearch.ForwBorder">F.Border</system:String>
<system:String x:Key="str.PgBorderSearch.BackwBorder">B.Border</system:String>
<system:String x:Key="str.PgBorderSearch.Width">Width</system:String>
<system:String x:Key="str.PgBorderSearch.ExpWidth">Exp. Width</system:String>
<system:String x:Key="str.PgBorderSearch.XRange">X Range</system:String>
<system:String x:Key="str.PgBorderSearch.YRange">Y Range</system:String>
...
...
Project.FLY.Thick.Base/FLY.Thick.Base.UI/Themes/StringResources/en/StringResource.PgCustomSections.xaml
View file @
c1f8800f
...
...
@@ -22,7 +22,8 @@
<system:String x:Key="str.PgCustomSections.XStep" >X-axis Step</system:String>
<system:String x:Key="str.PgCustomSections.SelectMusicFile" >Select Music File</system:String>
<system:String x:Key="str.PgCustomSections.IsSureToReboot">The App must be rebooted to execute new parameters. Do you want to reboot it?</system:String>
<system:String x:Key="str.PgCustomSections.Language">Language</system:String>
<system:String x:Key="str.PgCustomSections.Apply">Apply</system:String>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment