You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

I18N.cs 1.6 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
6 years ago
10 years ago
10 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. namespace Shadowsocks.Controller
  6. {
  7. using Shadowsocks.Properties;
  8. public static class I18N
  9. {
  10. private static Dictionary<string, string> _strings = new Dictionary<string, string>();
  11. private static void Init(string res)
  12. {
  13. using (var sr = new StringReader(res))
  14. {
  15. foreach (var line in sr.NonWhiteSpaceLines())
  16. {
  17. if (line[0] == '#')
  18. continue;
  19. var pos = line.IndexOf('=');
  20. if (pos < 1)
  21. continue;
  22. _strings[line.Substring(0, pos)] = line.Substring(pos + 1);
  23. }
  24. }
  25. }
  26. static I18N()
  27. {
  28. string name = CultureInfo.CurrentCulture.EnglishName;
  29. if (name.StartsWith("Chinese", StringComparison.OrdinalIgnoreCase))
  30. {
  31. // choose Traditional Chinese only if we get explicit indication
  32. Init(name.Contains("Traditional")
  33. ? Resources.zh_TW
  34. : Resources.zh_CN);
  35. }
  36. else if (name.StartsWith("Japan", StringComparison.OrdinalIgnoreCase))
  37. {
  38. Init(Resources.ja);
  39. }
  40. }
  41. public static string GetString(string key, params object[] args)
  42. {
  43. return string.Format(_strings.TryGetValue(key, out var value) ? value : key, args);
  44. }
  45. }
  46. }