Last active
May 21, 2025 21:21
-
-
Save koster/099cf277384674c50d8a664ddf544d87 to your computer and use it in GitHub Desktop.
A compact loc system that needs no setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just create a bunch LocString's anywhere | |
// change Loc.language and you're done | |
using System.Collections.Generic; | |
using System; | |
using System.Collections.Generic; | |
using System.Reflection; | |
public class LocString | |
{ | |
public string en; | |
public string ru; | |
Dictionary<string, FieldInfo> field = new Dictionary<string, FieldInfo>(); | |
public string GetText() | |
{ | |
if (!field.ContainsKey(Loc.language)) | |
{ | |
Type type = this.GetType(); | |
FieldInfo fieldInfo = type.GetField(Loc.language); | |
field.Add(Loc.language, fieldInfo); | |
} | |
return field[Loc.language].GetValue(this) as string; | |
} | |
public override string ToString() | |
{ | |
return GetText(); | |
} | |
} | |
public static class Loc | |
{ | |
public const string LANG_EN = "en"; | |
public const string LANG_RU = "ru"; | |
public static string language = LANG_EN; | |
public static List<string> langs = new List<string>() | |
{ | |
LANG_EN, | |
LANG_RU | |
}; | |
public static LocString test_string = new LocString() | |
{ | |
en = "I'm a test string", | |
ru = "Я тестовая строка" | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
label.text = Loc.test_string.ToString();