Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LocalizationStep.cs
1using System.Threading.Tasks;
4
6{
11 [TypeName(TypeNameSerialization.None)]
12 public class LocalizationStep
13 {
14 private int stringId;
15 private string module;
16 private string seed;
17
23 {
24 this.stringId = 0;
25 this.module = null;
26 this.seed = null;
27 }
28
35 {
36 this.stringId = StringId;
37 this.module = null;
38 this.seed = null;
39 }
40
47 public LocalizationStep(int StringId, string Module)
48 {
49 this.stringId = StringId;
50 this.module = Module;
51 this.seed = null;
52 }
53
61 public LocalizationStep(int StringId, string Module, string Seed)
62 {
63 this.stringId = StringId;
64 this.module = Module;
65 this.seed = Seed;
66 }
67
71 [ShortName("i")]
72 public int StringId
73 {
74 get => this.stringId;
75 set => this.stringId = value;
76 }
77
81 [DefaultValueNull]
82 [ShortName("m")]
83 public string Module
84 {
85 get => this.module;
86 set => this.module = value;
87 }
88
92 [DefaultValueNull]
93 [ShortName("s")]
94 public string Seed
95 {
96 get => this.seed;
97 set => this.seed = value;
98 }
99
107 public static async Task<string> TryGetLocalization(Language Language, Namespace BaseModule, params LocalizationStep[] Steps)
108 {
109 if (Steps is null || Steps.Length == 0)
110 return null;
111
112 string Result = Steps[0].seed ?? string.Empty;
113
115
116 foreach (LocalizationStep Step in Steps)
117 {
118 if (!string.IsNullOrEmpty(Step.module))
119 Namespace = await Language.GetNamespaceAsync(Step.module);
120 else
121 Namespace = BaseModule;
122
123 if (Namespace is null)
124 return null;
125
126 LanguageString String = await BaseModule.GetStringAsync(Step.stringId);
127 if (String is null)
128 return null;
129
130 Result = String.Value.Replace("%0%", Result);
131
132 if (!string.IsNullOrEmpty(Step.seed))
133 Result = Result.Replace("%1%", Step.seed);
134 }
135
136 return Result;
137 }
138 }
139}
Contains information about a language.
Definition: Language.cs:17
async Task< Namespace > GetNamespaceAsync(string Name)
Gets the namespace object, given its name, if available.
Definition: Language.cs:99
Contains a localized string.
Contains information about a namespace in a language.
Definition: Namespace.cs:17
Represents a localization step, as defined in XEP-323: http://xmpp.org/extensions/xep-0323....
string Seed
Optional localization seed.
static async Task< string > TryGetLocalization(Language Language, Namespace BaseModule, params LocalizationStep[] Steps)
Tries to get the localization of a string, given a sequence of localization steps.
string Module
Optional language module, if different from the base module.
LocalizationStep(int StringId)
Represents a localization step, as defined in XEP-323: http://xmpp.org/extensions/xep-0323....
LocalizationStep(int StringId, string Module)
Represents a localization step, as defined in XEP-323: http://xmpp.org/extensions/xep-0323....
LocalizationStep()
Represents a localization step, as defined in XEP-323: http://xmpp.org/extensions/xep-0323....
LocalizationStep(int StringId, string Module, string Seed)
Represents a localization step, as defined in XEP-323: http://xmpp.org/extensions/xep-0323....
TypeNameSerialization
How the type name should be serialized.