-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support providing different languages in appsettings
- Loading branch information
1 parent
0479c52
commit daad1c8
Showing
7 changed files
with
59 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace CaptchaBot.Services.Translation; | ||
|
||
public interface ITranslationService | ||
{ | ||
string GetWelcomeMessage(string prettyUserName, in int answer); | ||
} | ||
|
||
public class TranslationService : ITranslationService | ||
{ | ||
public TranslationService(IOptions<TranslationSettings> options) | ||
{ | ||
var settings = options.Value; | ||
|
||
NumberTexts = settings.NumberTexts.Split(','); | ||
WelcomeMessageTemplate = settings.WelcomeMessageTemplate; | ||
} | ||
|
||
private string[] NumberTexts { get; } | ||
|
||
private string WelcomeMessageTemplate { get; } | ||
|
||
private string GetRequestedNumberText(in int answer) => NumberTexts[answer]; | ||
|
||
public string GetWelcomeMessage(string prettyUserName, in int answer) | ||
=> string.Format(WelcomeMessageTemplate, prettyUserName, GetRequestedNumberText(answer)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace CaptchaBot.Services.Translation; | ||
|
||
public class TranslationSettings | ||
{ | ||
public string NumberTexts { get; set; } = "ноль,один,два,три,четыре,пять,шесть,семь,восемь"; | ||
|
||
public string WelcomeMessageTemplate { get; set; } = "Привет, {0}, нажми кнопку {1}, чтобы тебя не забанили!"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters