-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translations.cs
46 lines (44 loc) · 2.01 KB
/
Translations.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
global using static SFrequencyInfo.Translations;
namespace SFrequencyInfo
{
#region Translations for Main
partial class Main
{
public override TranslationList DefaultTranslations => DefaultTranslationList;
public new string Translate(string key, params object[] args) => base.Translate(key.Trim(TranslationKeyTrimCharacters), args);
}
#endregion
// Don't rename this class, it will be used in analyzer.
public static partial class Translations
{
#region Base
public static char[] TranslationKeyTrimCharacters = new[] { '_' };
/// <summary>
/// Retrieves values from <see cref="Translations"/> type. [Only "<see langword="public"/> <see langword="static"/> <see langword="readonly"/> <see langword="string"/>" or
/// "<see langword="public"/> <see langword="const"/> <see langword="string"/>" fields]
/// </summary>
public static TranslationList DefaultTranslationList
{
get
{
var translations = new TranslationList();
translations.AddRange(
typeof(Translations).GetFields(BindingFlags.Static | BindingFlags.Public)
.Where(x => (x.IsStatic && x.IsInitOnly) || x.IsLiteral)
.Select(x =>
new TranslationListEntry(x.Name.Trim(TranslationKeyTrimCharacters), (x.IsLiteral ? x.GetRawConstantValue() : x.GetValue(null)).ToString())
));
return translations;
}
}
/// <summary>
/// This method is important for analyzer!
/// </summary>
public static string Translate(string translationKey, params object[] arguments) => Main.Instance.Translate(translationKey, arguments);
#endregion
// You can write static/const string fields(translations) here. By default _ will be trimmed
public const string
Frequency = "Frequency of player {0} is '{1:000','000}'.",
NotFound = "Player '{0}' not found.";
}
}