Simply3DScan
Translate.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using Configuration;
5 using Logging;
6 using SharedObjects;
7 using PostSharp.Patterns.Contracts;
8 
9 namespace Translator
10 {
11  public class Translate
12  {
13  [Required]
14  private readonly Dictionary<string, string> germanDictionary = new Dictionary<string, string>();
15 
16  [Log]
17  [LogException]
18  public Translate()
19  {
20  this.ReadGermanDictionary();
21  }
22 
26  [LogException]
27  private void ReadGermanDictionary()
28  {
29  string line;
30  StreamReader file = new StreamReader("Deutsch.txt");
31  while ((line = file.ReadLine()) != null)
32  {
33  Console.WriteLine(line);
34  string[] values = line.Split('#');
35 
36  this.germanDictionary.Add(values[0], values[1]);
37  }
38 
39  file.Close();
40  }
41 
48  [LogException]
49  public string GetString(string englishString, Language language)
50  {
51  switch (language)
52  {
53  case Language.Deutsch:
54  if(this.germanDictionary.ContainsKey(englishString))
55  return this.germanDictionary[englishString];
56  Singleton<Logger>.Instance.LogWarning($"No translation for {englishString}");
57  return englishString;
58  case Language.English:
59  return englishString;
60  default:
61  Singleton<Logger>.Instance.LogWarning($"Language not supported {language}");
62  return englishString;
63  }
64  }
65  }
66 }
string GetString(string englishString, Language language)
Gets the translated string.
Definition: Translate.cs:49
Class for creating a singleton for a generic class
Definition: Singleton.cs:9
Definition: Logger.cs:5
static T Instance
Gets the instance.
Definition: Singleton.cs:27