From c9db2ce76ad1c939da192335426a2fb36742840c Mon Sep 17 00:00:00 2001 From: "Brett V. Forsgren" Date: Thu, 8 Feb 2018 13:31:11 -0800 Subject: [PATCH] add manual helper script to verify all translations --- src/scripts/VerifyAllTranslations.fsx | 39 +++++++++++++++++++++++++++ verify-translations.cmd | 3 +++ 2 files changed, 42 insertions(+) create mode 100644 src/scripts/VerifyAllTranslations.fsx create mode 100644 verify-translations.cmd diff --git a/src/scripts/VerifyAllTranslations.fsx b/src/scripts/VerifyAllTranslations.fsx new file mode 100644 index 000000000..24e2d4eeb --- /dev/null +++ b/src/scripts/VerifyAllTranslations.fsx @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +// verifies that all translations in all .xlf files have `state="translated"`. + +#r "System.Xml.Linq" + +open System +open System.IO +open System.Xml.Linq + +// usage: fsi VerifyAllTranslations.fsx -- baseDirectory +let baseDirectory = + Environment.GetCommandLineArgs() + |> Seq.skipWhile ((<>) "--") + |> Seq.skip 1 + |> Seq.head + +let hasUntranslatedStrings (xlfFile:string) = + let doc = XDocument.Load(xlfFile) + let untranslatedStates = + doc.Root.Descendants() + |> Seq.filter (fun (elem:XElement) -> elem.Name.LocalName = "target") + |> Seq.map (fun (elem:XElement) -> elem.Attribute(XName.op_Implicit("state"))) + |> Seq.filter (isNull >> not) + |> Seq.map (fun (attr:XAttribute) -> attr.Value) + |> Seq.filter ((<>) "translated") + Seq.length untranslatedStates > 0 + +let filesWithMissingTranslations = + Directory.EnumerateFiles(baseDirectory, "*.xlf", SearchOption.AllDirectories) + |> Seq.filter (fun (file:string) -> file.EndsWith(".en.xlf") |> not) // the english baseline files are never translated + |> Seq.filter hasUntranslatedStrings + |> Seq.toList + +match filesWithMissingTranslations with +| [] -> printfn "All .xlf files have translations assigned." +| _ -> + printfn "The following .xlf files have untranslated strings (state != 'translated'):\n\t%s" (String.Join("\n\t", filesWithMissingTranslations)) + Environment.Exit(1) diff --git a/verify-translations.cmd b/verify-translations.cmd new file mode 100644 index 000000000..6717de0f7 --- /dev/null +++ b/verify-translations.cmd @@ -0,0 +1,3 @@ +@echo off + +%~dp0release\net40\bin\fsi.exe %~dp0src\scripts\VerifyAllTranslations.fsx -- %~dp0