Skip to content

Commit 56014fc

Browse files
committed
REORG: Moved translation logic to base class for reuse, and enabled building from string source, so storing on file is not required.
1 parent 604fe63 commit 56014fc

File tree

5 files changed

+667
-503
lines changed

5 files changed

+667
-503
lines changed

FiftyOne.Pipeline.Elements/FiftyOne.Pipeline.Translation.Tests/TranslationEngineTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,42 @@ public void NoSourceKey()
103103
Assert.ThrowsException<ArgumentNullException>(builder.Build);
104104
}
105105

106+
/// <summary>
107+
/// Test that the engine can be built from a string source instead of a file,
108+
/// and that it correctly translates values based on that source.
109+
/// This is important to test as the string source is designed to be used
110+
/// with embedded resources, which are not passed as files.
111+
/// </summary>
112+
[TestMethod]
113+
public void BuildFromString()
114+
{
115+
var source =
116+
"cat: chat\ndog: chien";
117+
118+
var engine = new TranslationEngineBuilder(_loggerFactory)
119+
.SetSourceElementDataKey("evidencecopy")
120+
.AddSource("animals.fr_FR.yml", source)
121+
.AddTranslation("Animal", "AnimalTranslated")
122+
.Build();
123+
using var pipeline = new PipelineBuilder(_loggerFactory)
124+
.AddFlowElement(new EvidenceCopyElement(_loggerFactory.CreateLogger<EvidenceCopyElement>()))
125+
.AddFlowElement(engine)
126+
.SetSuppressProcessExceptions(true)
127+
.Build();
128+
129+
using var flowData = pipeline.CreateFlowData();
130+
131+
flowData.AddEvidence("header.accept-language", "fr_FR");
132+
flowData.AddEvidence("Animal", "dog");
133+
flowData.Process();
134+
135+
var result = flowData.Get<ITranslationData>();
136+
var translation = result["AnimalTranslated"];
137+
138+
Assert.IsNotNull(translation);
139+
Assert.AreEqual("chien", translation);
140+
}
141+
106142
/// <summary>
107143
/// Test that a list of strings is correctly translated.
108144
/// </summary>

FiftyOne.Pipeline.Elements/FiftyOne.Pipeline.Translation/FiftyOne.Pipeline.Translation.xml

Lines changed: 70 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)