diff --git a/OpenRA.Game/Translation.cs b/OpenRA.Game/Translation.cs index eaa29573a2..e3f01e7404 100644 --- a/OpenRA.Game/Translation.cs +++ b/OpenRA.Game/Translation.cs @@ -65,6 +65,23 @@ namespace OpenRA ParseTranslations(language, translations, fileSystem, onError); } + public Translation(string text, Action onError) + { + var parser = new LinguiniParser(text); + var resource = parser.Parse(); + foreach (var error in resource.Errors) + onError(error); + + bundle = LinguiniBuilder.Builder() + .CultureInfo(CultureInfo.InvariantCulture) + .SkipResources() + .SetUseIsolating(false) + .UseConcurrent() + .UncheckedBuild(); + + bundle.AddResourceOverriding(resource); + } + void ParseTranslations(string language, string[] translations, IReadOnlyFileSystem fileSystem, Action onError) { // Always load english strings to provide a fallback for missing translations. diff --git a/OpenRA.Test/OpenRA.Game/FluentTest.cs b/OpenRA.Test/OpenRA.Game/FluentTest.cs new file mode 100644 index 0000000000..6d33cef4aa --- /dev/null +++ b/OpenRA.Test/OpenRA.Game/FluentTest.cs @@ -0,0 +1,37 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using NUnit.Framework; + +namespace OpenRA.Test +{ + [TestFixture] + public class FluentTest + { + readonly string pluralForms = @" +label-players = {$player -> + [one] One player + *[other] {$player} players +} +"; + + [TestCase(TestName = "Fluent Plural Terms")] + public void TestOne() + { + var translation = new Translation(pluralForms, e => Console.WriteLine(e.Message)); + var label = translation.GetString("label-players", Translation.Arguments("player", 1)); + Assert.That("One player", Is.EqualTo(label)); + label = translation.GetString("label-players", Translation.Arguments("player", 2)); + Assert.That("2 players", Is.EqualTo(label)); + } + } +}