Terraria ModLoader  0.11.7.8
A mod to make and play Terraria mods
ModTranslation.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using Terraria.Localization;
4 
5 namespace Terraria.ModLoader
6 {
7  public class ModTranslation
8  {
9  private const int fallback = 1;
10  public readonly string Key;
11  private Dictionary<int, string> translations;
12 
13  internal ModTranslation(string key, bool defaultEmpty = false) {
14  if (key.Contains(" "))
15  throw new Exception("ModTranslation keys can't contain spaces.");
16  this.Key = key;
17  this.translations = new Dictionary<int, string>();
18  this.translations[fallback] = defaultEmpty ? null : key;
19  }
20 
21  public void SetDefault(string value) {
22  AddTranslation(fallback, value);
23  }
24 
25  public void AddTranslation(int culture, string value) {
26  translations[culture] = value;
27  }
28 
29  public void AddTranslation(string culture, string value) {
30  AddTranslation(GameCulture.FromName(culture).LegacyId, value);
31  }
32 
33  public void AddTranslation(GameCulture culture, string value) {
34  AddTranslation(culture.LegacyId, value);
35  }
36 
37  public bool IsDefault() {
38  return translations[fallback] == Key;
39  }
40 
41  public string GetDefault() {
42  return GetTranslation(fallback);
43  }
44 
45  public string GetTranslation(int culture) {
46  if (translations.ContainsKey(culture)) {
47  return translations[culture];
48  }
49  return translations[fallback];
50  }
51 
52  public string GetTranslation(string culture) {
53  return GetTranslation(GameCulture.FromName(culture).LegacyId);
54  }
55 
56  public string GetTranslation(GameCulture culture) {
57  return GetTranslation(culture.LegacyId);
58  }
59  }
60 }
void AddTranslation(int culture, string value)
string GetTranslation(GameCulture culture)
Dictionary< int, string > translations
void AddTranslation(string culture, string value)
void AddTranslation(GameCulture culture, string value)
string GetTranslation(string culture)
string GetTranslation(int culture)