Skip to content

Commit 8b18900

Browse files
committed
feat(languages): languages are now stored as resources, fixes gui window not always showing text correctly
1 parent 5b89353 commit 8b18900

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4582
-266
lines changed

compile.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ echo f | xcopy /s /y src\CSAuto_Mobile\bin\Release\net7.0-android33.0\com.murky.
3737
@echo Copied csauto_mobile apk
3838
@echo ------------------------------------------------------------------
3939
@echo Zipping csauto...
40-
tar -caf Output\CSAuto_Portable.zip -C src\CSAuto\bin\Release *.dll *.exe resource
40+
tar -caf Output\CSAuto_Portable.zip -C src\CSAuto\bin\Release *.dll *.exe resource ru
4141
@echo Zipped csauto
4242
@echo ------------------------------------------------------------------
4343
@echo Everything should be in the Output folder

installer.iss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescrip
4040
Source: "src\CSAuto\bin\Release\*.exe"; DestDir: "{app}"; Flags: ignoreversion
4141
Source: "src\CSAuto\bin\Release\*.dll"; DestDir: "{app}"; Flags: ignoreversion
4242
Source: "src\CSAuto\bin\Release\resource\*.pac"; DestDir: "{app}\resource"; Flags: ignoreversion
43+
Source: "src\CSAuto\bin\Release\ru\*"; DestDir: "{app}\ru"; Flags: ignoreversion
4344
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
4445

4546
[Icons]

src/CSAuto/App.xaml.cs

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Configuration;
99
using System.Data;
1010
using System.Diagnostics;
11+
using System.Globalization;
1112
using System.IO;
1213
using System.IO.Compression;
1314
using System.Linq;
@@ -61,11 +62,25 @@ protected override void OnStartup(StartupEventArgs e)
6162
if(oldSettingsExist)
6263
File.Delete(Log.WorkPath + "\\.tmp");
6364
}
64-
LoadLanguage(languageName?.ToLower());
65+
//LoadLanguage(languageName?.ToLower());
6566
buyMenu = new AutoBuyMenu();
6667
ImportSettings();
6768
ImportAutoBuy();
6869

70+
if (Settings.Default.currentLanguage.Contains("language"))
71+
{
72+
switch (Settings.Default.currentLanguage)
73+
{
74+
case "language_english":
75+
Settings.Default.currentLanguage = "en-EN";
76+
break;
77+
case "language_russian":
78+
Settings.Default.currentLanguage = "ru-RU";
79+
break;
80+
}
81+
}
82+
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(Settings.Default.currentLanguage);
83+
6984
base.OnStartup(e);
7085

7186
if (Settings.Default.darkTheme)
@@ -174,40 +189,40 @@ private bool WindowsDarkMode()
174189
catch { return false; }
175190
}
176191

177-
private void LoadLanguage(string languageName)
178-
{
179-
string[] englishFile = ReadLanguageFile($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\resource\\language_english.pac");
180-
string[] file = null;
181-
try { file = ReadLanguageFile($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\resource\\{(languageName == null ? Settings.Default.currentLanguage : "language_"+languageName)}.pac"); }
182-
catch (FileNotFoundException)
183-
{
184-
MessageBox.Show($"Couldn't load {(languageName == null ? Settings.Default.currentLanguage : "language_" + languageName)}, the app will fallback to english",
185-
"Warning",
186-
MessageBoxButton.OK,
187-
MessageBoxImage.Warning);
188-
}
189-
if(file!= null)
190-
{
191-
for (int i = 0; i < file.Length; i++)
192-
{
193-
string[] values = GetValues(file[i]);
194-
if (values != null && values[0] != null && values[1] != null)
195-
Languages._Language.translation.Add(values[0], values[1].Replace("\\n","\n"));
196-
}
197-
}
198-
for (int i = 0; i < englishFile.Length; i++)
199-
{
200-
string[] values = GetValues(englishFile[i]);
201-
if (values != null && values[0] != null && values[1] != null)
202-
Languages._Language.englishTranslation.Add(values[0], values[1].Replace("\\n", "\n"));
203-
}
204-
}
192+
//private void LoadLanguage(string languageName)
193+
//{
194+
// string[] englishFile = ReadLanguageFile($"{Log.WorkPath}\\resource\\lang\\language_english.pac");
195+
// string[] file = null;
196+
// try { file = ReadLanguageFile($"{Log.WorkPath}\\resource\\lang\\{(languageName == null ? Settings.Default.currentLanguage : "language_"+languageName)}.pac"); }
197+
// catch (FileNotFoundException)
198+
// {
199+
// MessageBox.Show($"Couldn't load {(languageName == null ? Settings.Default.currentLanguage : "language_" + languageName)}, the app will fallback to english",
200+
// "Warning",
201+
// MessageBoxButton.OK,
202+
// MessageBoxImage.Warning);
203+
// }
204+
// if(file!= null)
205+
// {
206+
// for (int i = 0; i < file.Length; i++)
207+
// {
208+
// string[] values = GetValues(file[i]);
209+
// if (values != null && values[0] != null && values[1] != null)
210+
// Languages._Language.translation.Add(values[0], values[1].Replace("\\n","\n"));
211+
// }
212+
// }
213+
// for (int i = 0; i < englishFile.Length; i++)
214+
// {
215+
// string[] values = GetValues(englishFile[i]);
216+
// if (values != null && values[0] != null && values[1] != null)
217+
// Languages._Language.englishTranslation.Add(values[0], values[1].Replace("\\n", "\n"));
218+
// }
219+
//}
205220

206-
private string[] ReadLanguageFile(string path)
207-
{
208-
string file = Unzip(File.ReadAllBytes(path));
209-
return file.Split('\n');
210-
}
221+
//private string[] ReadLanguageFile(string path)
222+
//{
223+
// string file = Unzip(File.ReadAllBytes(path));
224+
// return file.Split('\n');
225+
//}
211226
static void CopyTo(Stream src, Stream dest)
212227
{
213228
byte[] bytes = new byte[4096];
@@ -301,7 +316,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
301316
$"StackTrace:{ex.StackTrace}\n" +
302317
$"Source: {ex.Source}\n" +
303318
$"Inner Exception: {ex.InnerException}");
304-
MessageBox.Show(AppLanguage.Language["error_appcrashed"], AppLanguage.Language["title_error"] + $" ({frame.GetMethod().Name})", MessageBoxButton.OK, MessageBoxImage.Error);
319+
MessageBox.Show(Strings.ResourceManager.GetString("error_appcrashed"), Strings.ResourceManager.GetString("title_error") + $" ({frame.GetMethod().Name})", MessageBoxButton.OK, MessageBoxImage.Error);
305320
Process.Start(Log.WorkPath + "\\Error_Log.txt");
306321
Current.Shutdown();
307322
}

src/CSAuto/CSAuto.csproj

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<WarningLevel>4</WarningLevel>
1515
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1616
<Deterministic>true</Deterministic>
17+
<IsWebBootstrapper>false</IsWebBootstrapper>
18+
<NuGetPackageImportStamp>
19+
</NuGetPackageImportStamp>
1720
<PublishUrl>publish\</PublishUrl>
1821
<Install>true</Install>
1922
<InstallFrom>Disk</InstallFrom>
@@ -26,11 +29,8 @@
2629
<MapFileExtensions>true</MapFileExtensions>
2730
<ApplicationRevision>0</ApplicationRevision>
2831
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
29-
<IsWebBootstrapper>false</IsWebBootstrapper>
3032
<UseApplicationTrust>false</UseApplicationTrust>
3133
<BootstrapperEnabled>true</BootstrapperEnabled>
32-
<NuGetPackageImportStamp>
33-
</NuGetPackageImportStamp>
3434
</PropertyGroup>
3535
<PropertyGroup>
3636
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
@@ -106,7 +106,16 @@
106106
<Compile Include="Extentions.cs" />
107107
<Compile Include="ImageLoader.cs" />
108108
<Compile Include="Languages\AppLanguage.cs" />
109-
<Compile Include="Languages\_Language.cs" />
109+
<Compile Include="Properties\Strings.Designer.cs">
110+
<AutoGen>True</AutoGen>
111+
<DesignTime>True</DesignTime>
112+
<DependentUpon>Strings.resx</DependentUpon>
113+
</Compile>
114+
<Compile Include="Properties\Strings.ru.Designer.cs">
115+
<AutoGen>True</AutoGen>
116+
<DesignTime>True</DesignTime>
117+
<DependentUpon>Strings.ru.resx</DependentUpon>
118+
</Compile>
110119
<Compile Include="Utils\CSGO\ConDump.cs" />
111120
<Compile Include="Utils\DXGICapture.cs" />
112121
<Compile Include="Utils\Nager.TcpClient\TcpClient.cs" />
@@ -178,9 +187,17 @@
178187
<LastGenOutput>APIKeys.Designer.cs</LastGenOutput>
179188
</EmbeddedResource>
180189
<EmbeddedResource Include="Properties\Resources.resx">
181-
<Generator>ResXFileCodeGenerator</Generator>
190+
<Generator>PublicResXFileCodeGenerator</Generator>
182191
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
183192
</EmbeddedResource>
193+
<EmbeddedResource Include="Properties\Strings.resx">
194+
<Generator>PublicResXFileCodeGenerator</Generator>
195+
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
196+
</EmbeddedResource>
197+
<EmbeddedResource Include="Properties\Strings.ru.resx">
198+
<Generator>PublicResXFileCodeGenerator</Generator>
199+
<LastGenOutput>Strings.ru.Designer.cs</LastGenOutput>
200+
</EmbeddedResource>
184201
<None Include=".editorconfig" />
185202
<None Include="Properties\Settings.settings">
186203
<Generator>SettingsSingleFileGenerator</Generator>
@@ -235,12 +252,19 @@
235252
<Version>4.5.0</Version>
236253
</PackageReference>
237254
</ItemGroup>
255+
<ItemGroup>
256+
<Folder Include="Resources\" />
257+
</ItemGroup>
238258
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
239259
<PropertyGroup>
240-
<PreBuildEvent>call $(SolutionDir)Misc\prebuild.bat $(SolutionDir)
241-
call $(SolutionDir)Misc\stcmprs.exe $(ProjectDir)resource $(TargetDir)resource
260+
<PreBuildEvent>rm -r $(ProjectDir)$(OutDir)resource
261+
mkdir -r $(ProjectDir)$(OutDir)resource
262+
call $(SolutionDir)Misc\prebuild.bat $(SolutionDir)
242263
call $(SolutionDir)Misc\impack.exe $(ProjectDir)resource\images $(TargetDir)resource\images.pac
243-
rm -r $(ProjectDir)$(OutDir)resource\.portable
244264
copy $(ProjectDir)resource\.portable $(ProjectDir)$(OutDir)resource\.portable</PreBuildEvent>
245265
</PropertyGroup>
266+
<PropertyGroup>
267+
<PostBuildEvent>
268+
</PostBuildEvent>
269+
</PropertyGroup>
246270
</Project>

0 commit comments

Comments
 (0)