mirror of
https://github.com/chylex/Backup-Essentials.git
synced 2025-08-01 15:59:08 +02:00
Language supports strings with dynamic numbers + added docs
This commit is contained in:
parent
2a715905f9
commit
654e31ea43
@ -10,6 +10,9 @@ namespace BackupEssentials.Data{
|
||||
public string File { get; private set; }
|
||||
public string LangName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns translated text using language key. If there is no text assigned, the key itself is returned.
|
||||
/// </summary>
|
||||
public string this[string key] {
|
||||
get {
|
||||
if (Data.Count == 0)LoadLanguage();
|
||||
@ -19,14 +22,30 @@ namespace BackupEssentials.Data{
|
||||
}
|
||||
}
|
||||
|
||||
public string this[string key, params object[] data] {
|
||||
/// <summary>
|
||||
/// Returns translated text using language key. If there is no text assigned, the key itself is returned.
|
||||
/// This override allows parameters to be passed to the translated text. In the text, $x signifies an element of the data object array.
|
||||
/// </summary>
|
||||
public string this[string key, params string[] data] {
|
||||
get {
|
||||
string text = this[key];
|
||||
for(int a = data.Length-1; a >= 0; a--)text = text.Replace("$"+a,data[a].ToString());
|
||||
for(int a = data.Length-1; a >= 0; a--)text = text.Replace("$"+a,data[a]);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns translated text using language key with the number parameter. If the exact key with number parameter is not found, the one with an asterisk is returned.
|
||||
/// The key should be provided without the number, ending with a dot. The number will be added and checked automatically.
|
||||
/// This override allows parameters to be passed to the translated text. In the text, $x signifies an element of the data object array.
|
||||
/// </summary>
|
||||
public string this[string key, int paramNumber, params string[] data] {
|
||||
get {
|
||||
if (Data.ContainsKey(key+paramNumber))return this[key+paramNumber,data];
|
||||
else return this[key+"*",data];
|
||||
}
|
||||
}
|
||||
|
||||
public Language(string file, string langName){
|
||||
this.File = file;
|
||||
this.LangName = langName;
|
||||
|
Loading…
Reference in New Issue
Block a user