diff --git a/TelegramBotBase/Controls/ButtonGrid.cs b/TelegramBotBase/Controls/ButtonGrid.cs index 11d5796..7aed30f 100644 --- a/TelegramBotBase/Controls/ButtonGrid.cs +++ b/TelegramBotBase/Controls/ButtonGrid.cs @@ -18,7 +18,7 @@ namespace TelegramBotBase.Controls public class ButtonGrid : Base.ControlBase { - public String Title { get; set; } = "Toggle"; + public String Title { get; set; } = Localizations.Default.Language["ButtonGrid_Title"]; public String ConfirmationText { get; set; } = ""; diff --git a/TelegramBotBase/Controls/CalendarPicker.cs b/TelegramBotBase/Controls/CalendarPicker.cs index 5e51c63..f97e3ab 100644 --- a/TelegramBotBase/Controls/CalendarPicker.cs +++ b/TelegramBotBase/Controls/CalendarPicker.cs @@ -27,7 +27,7 @@ namespace TelegramBotBase.Controls private int? MessageId { get; set; } - public String Title { get; set; } = "Pick Date"; + public String Title { get; set; } = Localizations.Default.Language["CalendarPicker_Title"]; public eMonthPickerMode PickerMode { get; set; } @@ -55,7 +55,7 @@ namespace TelegramBotBase.Controls switch (result.RawData) { - case "next": + case "$next$": switch (this.PickerMode) { @@ -74,7 +74,7 @@ namespace TelegramBotBase.Controls break; - case "prev": + case "$prev$": switch (this.PickerMode) { @@ -93,7 +93,7 @@ namespace TelegramBotBase.Controls break; - case "monthtitle": + case "$monthtitle$": if (this.EnableMonthView) { @@ -102,7 +102,7 @@ namespace TelegramBotBase.Controls break; - case "yeartitle": + case "$yeartitle$": if (this.EnableYearView) { @@ -110,7 +110,7 @@ namespace TelegramBotBase.Controls } break; - case "yearstitle": + case "$yearstitle$": if (this.EnableMonthView) { @@ -179,7 +179,7 @@ namespace TelegramBotBase.Controls string[] dayNamesNormal = this.Culture.DateTimeFormat.ShortestDayNames; string[] dayNamesShifted = Shift(dayNamesNormal, (int)this.FirstDayOfWeek); - bf.AddButtonRow(new ButtonBase("<<", "prev"), new ButtonBase(this.Culture.DateTimeFormat.MonthNames[month.Month - 1] + " " + month.Year.ToString(), "monthtitle"), new ButtonBase(">>", "next")); + bf.AddButtonRow(new ButtonBase(Localizations.Default.Language["CalendarPicker_PreviousPage"], "$prev$"), new ButtonBase(this.Culture.DateTimeFormat.MonthNames[month.Month - 1] + " " + month.Year.ToString(), "$monthtitle$"), new ButtonBase(Localizations.Default.Language["CalendarPicker_NextPage"], "$next$")); bf.AddButtonRow(dayNamesShifted.Select(a => new ButtonBase(a, a)).ToList()); @@ -223,7 +223,7 @@ namespace TelegramBotBase.Controls case eMonthPickerMode.month: - bf.AddButtonRow(new ButtonBase("<<", "prev"), new ButtonBase(this.VisibleMonth.Year.ToString("0000"), "yeartitle"), new ButtonBase(">>", "next")); + bf.AddButtonRow(new ButtonBase(Localizations.Default.Language["CalendarPicker_PreviousPage"], "$prev$"), new ButtonBase(this.VisibleMonth.Year.ToString("0000"), "$yeartitle$"), new ButtonBase(Localizations.Default.Language["CalendarPicker_NextPage"], "$next$")); var months = this.Culture.DateTimeFormat.MonthNames; @@ -235,7 +235,7 @@ namespace TelegramBotBase.Controls case eMonthPickerMode.year: - bf.AddButtonRow(new ButtonBase("<<", "prev"), new ButtonBase("Year", "yearstitle"), new ButtonBase(">>", "next")); + bf.AddButtonRow(new ButtonBase(Localizations.Default.Language["CalendarPicker_PreviousPage"], "$prev$"), new ButtonBase("Year", "$yearstitle$"), new ButtonBase(Localizations.Default.Language["CalendarPicker_NextPage"], "$next$")); var starti = Math.Floor(this.VisibleMonth.Year / 10f) * 10; diff --git a/TelegramBotBase/Controls/ToggleButton.cs b/TelegramBotBase/Controls/ToggleButton.cs index 4adcd3f..afecb11 100644 --- a/TelegramBotBase/Controls/ToggleButton.cs +++ b/TelegramBotBase/Controls/ToggleButton.cs @@ -12,15 +12,15 @@ namespace TelegramBotBase.Controls public class ToggleButton : ControlBase { - public String UncheckedIcon { get; set; } = "⚪"; + public String UncheckedIcon { get; set; } = Localizations.Default.Language["ToggleButton_OffIcon"]; - public String CheckedIcon { get; set; } = "⚫"; + public String CheckedIcon { get; set; } = Localizations.Default.Language["ToggleButton_OnIcon"]; - public String CheckedString { get; set; } = "On"; + public String CheckedString { get; set; } = Localizations.Default.Language["ToggleButton_On"]; - public String UncheckedString { get; set; } = "Off"; + public String UncheckedString { get; set; } = Localizations.Default.Language["ToggleButton_Off"]; - public String Title { get; set; } = "Toggle"; + public String Title { get; set; } = Localizations.Default.Language["ToggleButton_Title"]; public int? MessageId { get; set; } diff --git a/TelegramBotBase/Controls/TreeView.cs b/TelegramBotBase/Controls/TreeView.cs index cdb7d3c..1c59463 100644 --- a/TelegramBotBase/Controls/TreeView.cs +++ b/TelegramBotBase/Controls/TreeView.cs @@ -20,12 +20,12 @@ namespace TelegramBotBase.Controls private int? MessageId { get; set; } - public String MoveUpIcon { get; set; } = "🔼 up"; + public String MoveUpIcon { get; set; } = Localizations.Default.Language["TreeView_LevelUp"]; public TreeView() { this.Nodes = new List(); - this.Title = "Select node"; + this.Title = Localizations.Default.Language["TreeView_Title"]; } @@ -52,19 +52,21 @@ namespace TelegramBotBase.Controls var n = (this.VisibleNode != null ? this.VisibleNode.FindNodeByValue(val) : this.Nodes.FirstOrDefault(a => a.Value == val)); - if (n != null) - { - if (n.ChildNodes.Count > 0) - { - this.VisibleNode = n; - } - else - { - this.SelectedNode = (this.SelectedNode != n ? n : null); - } + if (n == null) + return; - result.Handled = true; + + if (n.ChildNodes.Count > 0) + { + this.VisibleNode = n; } + else + { + this.SelectedNode = (this.SelectedNode != n ? n : null); + } + + result.Handled = true; + break; diff --git a/TelegramBotBase/Form/PromptDialog.cs b/TelegramBotBase/Form/PromptDialog.cs index caad5d9..ad33207 100644 --- a/TelegramBotBase/Form/PromptDialog.cs +++ b/TelegramBotBase/Form/PromptDialog.cs @@ -21,7 +21,7 @@ namespace TelegramBotBase.Form public bool ShowBackButton { get; set; } = false; - public String BackLabel { get; set; } = "Zurück"; + public String BackLabel { get; set; } = Localizations.Default.Language["PromptDialog_Back"]; public PromptDialog() { diff --git a/TelegramBotBase/Localizations/Default.cs b/TelegramBotBase/Localizations/Default.cs new file mode 100644 index 0000000..6b0a180 --- /dev/null +++ b/TelegramBotBase/Localizations/Default.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Localizations +{ + public static class Default + { + + public static Localization Language = new English(); + + + } +} diff --git a/TelegramBotBase/Localizations/English.cs b/TelegramBotBase/Localizations/English.cs new file mode 100644 index 0000000..946037b --- /dev/null +++ b/TelegramBotBase/Localizations/English.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Localizations +{ + public class English : Localization + { + public English() : base() + { + Values["Language"] = "English"; + Values["ButtonGrid_Title"] = "Menu"; + Values["ButtonGrid_NoItems"] = "There are no items."; + Values["ButtonGrid_CurrentPage"] = "Page {0} of {1}"; + Values["CalendarPicker_Title"] = "Pick date"; + Values["TreeView_Title"] = "Select node"; + Values["TreeView_LevelUp"] = "🔼 level up"; + Values["ToggleButton_On"] = "On"; + Values["ToggleButton_Off"] = "Off"; + Values["ToggleButton_Title"] = "Toggle"; + } + + + } +} diff --git a/TelegramBotBase/Localizations/German.cs b/TelegramBotBase/Localizations/German.cs new file mode 100644 index 0000000..1672959 --- /dev/null +++ b/TelegramBotBase/Localizations/German.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Localizations +{ + public class German : Localization + { + public German() : base() + { + + } + + + } +} diff --git a/TelegramBotBase/Localizations/Localization.cs b/TelegramBotBase/Localizations/Localization.cs new file mode 100644 index 0000000..97f0793 --- /dev/null +++ b/TelegramBotBase/Localizations/Localization.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Localizations +{ + public class Localization + { + public Dictionary Values = new Dictionary(); + + public String this[String key] + { + get + { + return Values[key]; + } + } + + public Localization() + { + Values["Language"] = "Deutsch (German)"; + Values["ButtonGrid_Title"] = "Menü"; + Values["CalendarPicker_Title"] = "Datum auswählen"; + Values["CalendarPicker_PreviousPage"] = "◀️"; + Values["CalendarPicker_NextPage"] = "▶️"; + Values["TreeView_Title"] = "Knoten auswählen"; + Values["TreeView_LevelUp"] = "🔼 Stufe hoch"; + Values["ToggleButton_On"] = "An"; + Values["ToggleButton_Off"] = "Aus"; + Values["ToggleButton_OnIcon"] = "⚫"; + Values["ToggleButton_OffIcon"] = "⚪"; + Values["ToggleButton_Title"] = "Schalter"; + Values["PromptDialog_Back"] = "Zurück"; + + } + + } +} +