This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 322
/
Copy pathInternational.cs
98 lines (84 loc) · 2.96 KB
/
International.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Newtonsoft.Json;
using NiceHashMiner.Enums;
namespace NiceHashMiner
{
class International
{
private class Language
{
#pragma warning disable 649
public string Name;
public LanguageType ID;
public Dictionary<string, string> Entries;
#pragma warning restore 649
}
private static Language SelectedLanguage;
private static List<Language> GetLanguages()
{
List<Language> langs = new List<Language>();
try
{
DirectoryInfo di = new DirectoryInfo("langs");
FileInfo[] files = di.GetFiles("*.lang");
foreach (FileInfo fi in files)
{
try
{
Language l = JsonConvert.DeserializeObject<Language>(File.ReadAllText(fi.FullName)); // TODO , Globals.JsonSettings not sure since data must be localized
langs.Add(l);
}
catch (Exception ex)
{
Helpers.ConsolePrint("NICEHASH", "Lang error: " + ex.Message);
}
}
}
catch (Exception ex)
{
Helpers.ConsolePrint("NICEHASH", "Lang error: " + ex.Message);
}
return langs;
}
public static void Initialize(LanguageType lid)
{
List<Language> langs = GetLanguages();
foreach (Language lang in langs)
{
if (lang.ID == lid)
{
Helpers.ConsolePrint("NICEHASH", "Selected language: " + lang.Name);
SelectedLanguage = lang;
return;
}
}
Helpers.ConsolePrint("NICEHASH", "Critical error: missing language");
}
/// <summary>
/// Call this method to obtain available languages. Used by Settings GUI.
/// </summary>
/// <returns>Each dictionary entry contains id of the language (int) and name of the language (string).</returns>
public static Dictionary<LanguageType, string> GetAvailableLanguages()
{
List<Language> langs = GetLanguages();
Dictionary<LanguageType, string> retdict = new Dictionary<LanguageType, string>();
foreach (Language lang in langs)
{
Helpers.ConsolePrint("NICEHASH", "Found language: " + lang.Name);
retdict.Add(lang.ID, lang.Name);
}
return retdict;
}
public static string GetText(string token)
{
if (SelectedLanguage == null) return "";
if (SelectedLanguage.Entries.ContainsKey(token))
return SelectedLanguage.Entries[token];
else
return "";
}
}
}