Delete the TranslationHandler and the old translations file. Refactor GeekbotCommandBase to get the server language from guild settings. Create DateLocalization to create a localized relative time remaining string.

This commit is contained in:
runebaas 2020-08-14 23:15:11 +02:00
parent 078c884df7
commit 33829e91bc
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
22 changed files with 156 additions and 579 deletions

View file

@ -1,71 +0,0 @@
using System;
using System.Collections.Generic;
using Geekbot.Core.Localization;
using Moq;
using Xunit;
namespace Tests.Core.Localization
{
public class TranslationGuildContext_test
{
public class FormatDateTimeAsRemainingTestDto
{
public DateTimeOffset DateTime { get; set; }
public string Expected { get; set; }
}
public static TestData<FormatDateTimeAsRemainingTestDto> FormatDateTimeAsRemainingData =>
new TestData<FormatDateTimeAsRemainingTestDto>
{
{
"Wait for days",
new FormatDateTimeAsRemainingTestDto
{
DateTime = DateTimeOffset.Now.AddDays(5),
Expected = "4 days, 23 hours, 59 minutes and 59 seconds"
}
},
{
"Wait for minutes",
new FormatDateTimeAsRemainingTestDto
{
DateTime = DateTimeOffset.Now.AddMinutes(5),
Expected = "4 minutes and 59 seconds"
}
},
{
"Wait for seconds",
new FormatDateTimeAsRemainingTestDto
{
DateTime = DateTimeOffset.Now.AddSeconds(5),
Expected = "4 seconds"
}
}
};
[Theory, MemberData(nameof(FormatDateTimeAsRemainingData))]
public void FormatDateTimeAsRemaining(string testName, FormatDateTimeAsRemainingTestDto testData)
{
var translationHandlerMock = new Mock<ITranslationHandler>(MockBehavior.Loose);
translationHandlerMock
.Setup(thm => thm.GetString("EN", "dateTime", "Days"))
.Returns("day|days");
translationHandlerMock
.Setup(thm => thm.GetString("EN", "dateTime", "Hours"))
.Returns("hour|hours");
translationHandlerMock
.Setup(thm => thm.GetString("EN", "dateTime", "Minutes"))
.Returns("minute|minutes");
translationHandlerMock
.Setup(thm => thm.GetString("EN", "dateTime", "Seconds"))
.Returns("second|seconds");
translationHandlerMock
.Setup(thm => thm.GetString("EN", "dateTime", "And"))
.Returns("and");
var context = new TranslationGuildContext(translationHandlerMock.Object, "EN", new Dictionary<string, string>());
var result = context.FormatDateTimeAsRemaining(testData.DateTime);
Assert.Equal(result, testData.Expected);
}
}
}

View file

@ -1,46 +0,0 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Xunit;
using YamlDotNet.Core;
using YamlDotNet.Serialization;
namespace Tests.Core.Localization
{
public class Translations_test
{
[Fact]
public void TranslationsYamlIsValid()
{
// Read the file
var translationFile = File.ReadAllText(Path.GetFullPath("./../../../../src/Core/Localization/Translations.yml"));
// Deserialize
var input = new StringReader(translationFile);
var mergingParser = new MergingParser(new Parser(input));
var deserializer = new DeserializerBuilder().Build();
var rawTranslations = deserializer.Deserialize<Dictionary<string, Dictionary<string, Dictionary<string, string>>>>(mergingParser);
// These languages must be supported
var supportedLanguages = new List<string>
{
"EN",
"CHDE"
};
// Iterate every single key to make sure it's populated
foreach (var command in rawTranslations)
{
foreach (var str in command.Value)
{
str.Value.Select(e => e.Key).ToList().Should().BeEquivalentTo(supportedLanguages, str.Key);
foreach (var lang in str.Value)
{
lang.Value.Should().NotBeNullOrEmpty($"{command.Key} / {str.Key} / {lang.Key}");
}
}
}
}
}
}