Adding localization selection step to BotBaseBuilder
- Adding localization step - Updating test project
This commit is contained in:
parent
4bd43de0fe
commit
2c58f86524
@ -9,11 +9,12 @@ using TelegramBotBase.Builder.Interfaces;
|
||||
using TelegramBotBase.Commands;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
using TelegramBotBase.Localizations;
|
||||
using TelegramBotBase.States;
|
||||
|
||||
namespace TelegramBotBase.Builder
|
||||
{
|
||||
public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage
|
||||
public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage, ILanguageSelectionStage
|
||||
{
|
||||
|
||||
String _apiKey = null;
|
||||
@ -156,36 +157,59 @@ namespace TelegramBotBase.Builder
|
||||
}
|
||||
|
||||
|
||||
public IBuildingStage NoSerialization()
|
||||
public ILanguageSelectionStage NoSerialization()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage UseSerialization(IStateMachine machine)
|
||||
public ILanguageSelectionStage UseSerialization(IStateMachine machine)
|
||||
{
|
||||
this._statemachine = machine;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IBuildingStage UseJSON(string path)
|
||||
public ILanguageSelectionStage UseJSON(string path)
|
||||
{
|
||||
this._statemachine = new JSONStateMachine(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage UseSimpleJSON(string path)
|
||||
public ILanguageSelectionStage UseSimpleJSON(string path)
|
||||
{
|
||||
this._statemachine = new SimpleJSONStateMachine(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage UseXML(string path)
|
||||
public ILanguageSelectionStage UseXML(string path)
|
||||
{
|
||||
this._statemachine = new XMLStateMachine(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage DefaultLanguage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage UseEnglish()
|
||||
{
|
||||
Localizations.Default.Language = new Localizations.English();
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage UseGerman()
|
||||
{
|
||||
Localizations.Default.Language = new Localizations.German();
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage Custom(Localization language)
|
||||
{
|
||||
Localizations.Default.Language = language;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BotBase Build()
|
||||
{
|
||||
var bb = new BotBase();
|
||||
@ -208,5 +232,6 @@ namespace TelegramBotBase.Builder
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
36
TelegramBotBase/Builder/Interfaces/ILanguageStage.cs
Normal file
36
TelegramBotBase/Builder/Interfaces/ILanguageStage.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TelegramBotBase.Localizations;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
public interface ILanguageSelectionStage
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Selects the default language for control usage. (English)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IBuildingStage DefaultLanguage();
|
||||
|
||||
/// <summary>
|
||||
/// Selects english as the default language for control labels.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IBuildingStage UseEnglish();
|
||||
|
||||
/// <summary>
|
||||
/// Selects german as the default language for control labels.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IBuildingStage UseGerman();
|
||||
|
||||
/// <summary>
|
||||
/// Selects a custom language as the default language for control labels.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IBuildingStage Custom(Localization language);
|
||||
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,7 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// Do not uses serialization.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IBuildingStage NoSerialization();
|
||||
ILanguageSelectionStage NoSerialization();
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -19,7 +19,7 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="machine"></param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage UseSerialization(IStateMachine machine);
|
||||
ILanguageSelectionStage UseSerialization(IStateMachine machine);
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -27,7 +27,7 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage UseJSON(String path);
|
||||
ILanguageSelectionStage UseJSON(String path);
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -35,7 +35,7 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage UseSimpleJSON(String path);
|
||||
ILanguageSelectionStage UseSimpleJSON(String path);
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -43,7 +43,7 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage UseXML(String path);
|
||||
ILanguageSelectionStage UseXML(String path);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,11 +34,10 @@ namespace TelegramBotBaseTest
|
||||
a.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." });
|
||||
})
|
||||
.NoSerialization()
|
||||
.UseEnglish()
|
||||
.Build();
|
||||
|
||||
|
||||
|
||||
|
||||
bb.BotCommand += async (s, en) =>
|
||||
{
|
||||
switch (en.Command)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user