Add a test case for Fluent plural forms.

This commit is contained in:
Matthias Mailänder
2023-05-22 21:44:33 +02:00
committed by abcdefg30
parent dd9ab16401
commit 8a9426a0d4
2 changed files with 54 additions and 0 deletions

View File

@@ -65,6 +65,23 @@ namespace OpenRA
ParseTranslations(language, translations, fileSystem, onError);
}
public Translation(string text, Action<ParseError> 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<ParseError> onError)
{
// Always load english strings to provide a fallback for missing translations.

View File

@@ -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));
}
}
}