Add a test case for Fluent plural forms.
This commit is contained in:
committed by
abcdefg30
parent
dd9ab16401
commit
8a9426a0d4
@@ -65,6 +65,23 @@ namespace OpenRA
|
|||||||
ParseTranslations(language, translations, fileSystem, onError);
|
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)
|
void ParseTranslations(string language, string[] translations, IReadOnlyFileSystem fileSystem, Action<ParseError> onError)
|
||||||
{
|
{
|
||||||
// Always load english strings to provide a fallback for missing translations.
|
// Always load english strings to provide a fallback for missing translations.
|
||||||
|
|||||||
37
OpenRA.Test/OpenRA.Game/FluentTest.cs
Normal file
37
OpenRA.Test/OpenRA.Game/FluentTest.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user