[msbuild] Updating LocalizationStringTest (#9889)
Adding a test to check a specific error code to see if the strings in other locales are translated. This test will be added to the Localization wiki in Maccore accessible to the xamarin-macios team: https://github.com/xamarin/maccore/wiki/Localization
This commit is contained in:
Родитель
f8b66658c5
Коммит
369c3f8668
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
@ -5,6 +6,7 @@ using NUnit.Framework;
|
|||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Localization.MSBuild;
|
||||
|
||||
namespace Xamarin.iOS.Tasks {
|
||||
[TestFixture]
|
||||
|
@ -41,5 +43,45 @@ namespace Xamarin.iOS.Tasks {
|
|||
Thread.CurrentThread.CurrentUICulture = originalCulture;
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase ("cs-CZ")]
|
||||
[TestCase ("de-DE")]
|
||||
[TestCase ("es-ES")]
|
||||
[TestCase ("fr-FR")]
|
||||
[TestCase ("it-IT")]
|
||||
[TestCase ("ja-JP")]
|
||||
[TestCase ("ko-KR")]
|
||||
[TestCase ("pl-PL")]
|
||||
[TestCase ("pt-BR")]
|
||||
[TestCase ("ru-RU")]
|
||||
[TestCase ("tr-TR")]
|
||||
[TestCase ("zh-CN")]
|
||||
[TestCase ("zh-TW")]
|
||||
public void SpecificErrorTranslation (string culture)
|
||||
{
|
||||
// insert which error code you'd like to test
|
||||
string errorCode = "E0007";
|
||||
CultureInfo originalCulture = Thread.CurrentThread.CurrentUICulture;
|
||||
|
||||
try {
|
||||
Assert.IsFalse (string.IsNullOrEmpty (errorCode), "Error code is null or empty");
|
||||
string englishError = TranslateError ("en-US", errorCode);
|
||||
string newCultureError = TranslateError (culture, errorCode);
|
||||
|
||||
Assert.AreNotEqual (englishError, newCultureError, $"\"{errorCode}\" is not translated in {culture}.");
|
||||
} catch (NullReferenceException){
|
||||
Assert.IsFalse (true, $"Error code \"{errorCode}\" was not found");
|
||||
} finally {
|
||||
Thread.CurrentThread.CurrentUICulture = originalCulture;
|
||||
}
|
||||
}
|
||||
|
||||
private string TranslateError (string culture, string errorCode)
|
||||
{
|
||||
CultureInfo cultureInfo = new CultureInfo (culture);
|
||||
Thread.CurrentThread.CurrentUICulture = cultureInfo;
|
||||
PropertyInfo propertyInfo = typeof (MSBStrings).GetProperty (errorCode);
|
||||
return (string) propertyInfo.GetValue (null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<Reference Include="Microsoft.Build.Tasks.Core" HintPath="$(MSBuildBinPath)\Microsoft.Build.Tasks.Core.dll" />
|
||||
<Reference Include="Microsoft.Build.Utilities.Core" HintPath="$(MSBuildBinPath)\Microsoft.Build.Utilities.Core.dll" />
|
||||
<Reference Include="Xamarin.iOS.Tasks" HintPath="..\..\..\msbuild\Xamarin.iOS.Tasks\bin\$(Configuration)\netstandard2.0\Xamarin.iOS.Tasks.dll" />
|
||||
<Reference Include="Xamarin.Localization.MSBuild" HintPath="..\..\..\msbuild\Xamarin.iOS.Tasks\bin\$(Configuration)\netstandard2.0\Xamarin.Localization.MSBuild.dll" />
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit.ConsoleRunner" Version="3.11.1" />
|
||||
<PackageReference Include="NUnit.Extension.NUnitV2ResultWriter" Version="3.6.0" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче