diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationIgnore/common-Translations.ignore b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationIgnore/common-Translations.ignore new file mode 100644 index 0000000000..19a09a8ac4 --- /dev/null +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationIgnore/common-Translations.ignore @@ -0,0 +1,4 @@ +# Insert Error codes that are waiting on translations below (one per line) +W0111 +E7069 +E7070 diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationStringTest.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationStringTest.cs index 53cd14cda2..889a74a9a1 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationStringTest.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationStringTest.cs @@ -7,6 +7,9 @@ using System.Globalization; using System.Threading; using System.Collections.Generic; using Xamarin.Localization.MSBuild; +using System.ComponentModel; +using System.Linq; +using System.Text; namespace Xamarin.iOS.Tasks { [TestFixture] @@ -83,5 +86,73 @@ namespace Xamarin.iOS.Tasks { PropertyInfo propertyInfo = typeof (MSBStrings).GetProperty (errorCode); return (string) propertyInfo.GetValue (null, null); } + + IList commonIgnoreList = null; + static string shortCommonPath = "xamarin-macios/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationIgnore/common-Translations.ignore"; + + [SetUp] + public void SetUp () + { + commonIgnoreList = ReadFile ($"{Directory.GetCurrentDirectory ()}/TaskTests/LocalizationIgnore/common-Translations.ignore"); + } + + [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 AllErrorTranslation (string culture) + { + StringBuilder errorList = new StringBuilder (string.Empty); + IList cultureIgnoreList = null; + List commonValidEntries = new List (); + List cultureValidEntries = new List (); + + string fullCulturePath = $"{Directory.GetCurrentDirectory ()}/TaskTests/LocalizationIgnore/{culture}-Translations.ignore"; + string shortCulturePath = $"xamarin-macios/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/LocalizationIgnore/{culture}-Translations.ignore"; + CultureInfo originalCulture = Thread.CurrentThread.CurrentUICulture; + + cultureIgnoreList = ReadFile (fullCulturePath); + + foreach (var errorCodeInfo in typeof (MSBStrings).GetProperties ()) { + try { + var errorCode = errorCodeInfo.Name; + if (errorCode == "ResourceManager" || errorCode == "Culture") + continue; + string englishError = TranslateError ("en-US", errorCode); + string newCultureError = TranslateError (culture, errorCode); + + if (commonIgnoreList.Contains (errorCode)) { + Assert.AreEqual (englishError, newCultureError, $"{errorCode} is translated. Remove {errorCode} from {shortCommonPath}"); + commonValidEntries.Add (errorCode); + } else if (cultureIgnoreList.Contains (errorCode)) { + Assert.AreEqual (englishError, newCultureError, $"{errorCode} is translated. Remove {errorCode} from {shortCulturePath}"); + cultureValidEntries.Add (errorCode); + } else if (englishError == newCultureError) + errorList.Append ($"{errorCode} "); + } finally { + Thread.CurrentThread.CurrentUICulture = originalCulture; + } + } + + Assert.IsEmpty (errorList.ToString (), $"The following errors were not translated. Add them to {shortCommonPath} or {shortCulturePath}"); + Assert.IsEmpty (cultureIgnoreList.Except (cultureValidEntries), $"Not all error codes in {shortCulturePath} are valid or are repeated. Please remove."); + Assert.IsEmpty (commonIgnoreList.Except (commonValidEntries), $"Not all error codes in {shortCommonPath} are valid or are repeated. Please remove."); + } + + IList ReadFile (string path) + { + if (!File.Exists (path)) + return Array.Empty (); + return File.ReadAllLines (path).Where (line => !line.StartsWith ("#", StringComparison.Ordinal) && line != string.Empty).ToList (); + } } }