public override bool Execute() { var xlfDocument = new XlfDocument(XlfPath); if (!string.IsNullOrEmpty(ReplaceWithTestString) && ReplaceWithTestString.Equals("true")) { ReplaceResourceValuesWithTestString(xlfDocument); } xlfDocument.SaveAsResX(ResxPath); return !Log.HasLoggedErrors; }
public override bool Execute() { var xlfDocument = new XlfDocument(XlfPath); if (!string.IsNullOrEmpty(ReplaceWithTestString) && ReplaceWithTestString.Equals("true")) { ReplaceResourceValuesWithTestString(xlfDocument); } xlfDocument.SaveAsResX(ResxPath); return(!Log.HasLoggedErrors); }
public void SaveAsResX() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); string resXFile = System.IO.Path.GetTempFileName(); string resXFile2 = System.IO.Path.GetTempFileName(); try { doc.SaveAsResX(resXFile); Assert.IsFalse(File.ReadAllText(resXFile).Contains("<comment>Comment for a</comment>"), "SaveAsResX does not write comments per default"); doc.SaveAsResX(resXFile2, XlfDocument.ResXSaveOption.IncludeComments); Assert.IsTrue(File.ReadAllText(resXFile2).Contains("<comment>Comment for a</comment>"), "SaveAsResX must include comments when specified so"); } finally { System.IO.File.Delete(resXFile); System.IO.File.Delete(resXFile2); } } }
private static void ConvertXlfToResx(string xlfDirectory) { // convert xlf -> resx foreach (var xlfFile in EnumerateLocalizedFiles(xlfDirectory, "*.xlf")) { var xlfDocument = new XlfDocument(xlfFile); foreach (var language in s_languages) { var translatedResxFile = Path.ChangeExtension( Path.Combine( Path.GetDirectoryName(xlfDirectory), Path.GetFileName(xlfFile)), ".resx"); xlfDocument.SaveAsResX(translatedResxFile); } } }
private static void ConvertXlfToResx(string xlfDirectory, string resxFile) { foreach (var xlfFile in EnumerateLocalizedFiles(xlfDirectory, $"{Path.GetFileNameWithoutExtension(resxFile)}.*.xlf")) { if (xlfFile.Contains(".vsct.") != resxFile.Contains(".vsct.")) { // quick fix to deal with vsct and resx with same base name continue; } var xlfDocument = new XlfDocument(xlfFile); var translatedResxFile = Path.ChangeExtension( Path.Combine( Path.GetDirectoryName(xlfDirectory), Path.GetFileName(xlfFile)), ".resx"); xlfDocument.SaveAsResX(translatedResxFile); } }
public bool Execute(string projectDir) { List <string> filesOutputted = new List <string>(); Dictionary <string, List <ResXEntry> > parsedSourceFiles = new Dictionary <string, List <ResXEntry> >(); try { foreach (var file in Directory.GetFiles(projectDir, "*.xlf", SearchOption.AllDirectories)) { var doc = new XlfDocument(file); var xlfFile = doc.Files.Single(); // The two-char language code string targetLanguageCode = Path.GetFileName(file).Split('.').Reverse().ElementAt(1); // Original seems to include project directory in path, so we go up one level first, and then we need to get just the directory string originalFile = Path.Combine(Directory.GetParent(projectDir).FullName, xlfFile.Original.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)); if (!File.Exists(originalFile)) { Log.LogError("Original file not found at path: " + originalFile); return(false); } string outDir = Path.GetDirectoryName(originalFile); string originalFileName = Path.GetFileName(originalFile); string outFileName = Path.Combine(outDir, $"{Path.GetFileNameWithoutExtension(originalFileName)}.{targetLanguageCode}.resx"); // First update the XLF file List <ResXEntry> parsedSourceFile; if (!parsedSourceFiles.TryGetValue(originalFile, out parsedSourceFile)) { try { parsedSourceFile = ResXFile.Read(originalFile); parsedSourceFiles[originalFile] = parsedSourceFile; } catch (Exception ex) { Log.LogError("Invalid source file: " + originalFile + ". " + ex.ToString()); return(false); } } UpdateXlfFile(doc, parsedSourceFile); doc.SaveAsResX(outFileName); Log.LogMessage("Exported " + outFileName); filesOutputted.Add(outFileName); } } catch (Exception ex) { Log.LogErrorFromException(ex); return(false); } finally { //if (filesOutputted.Count > 0) //{ // File.WriteAllText("XliffCompilerWrittenFiles.txt", string.Join("\n", filesOutputted)); //} } return(true); }