/// ------------------------------------------------------------------------------------ /// <summary> /// Saves the XLIFFDocument to the specified XLIFF file. /// </summary> /// ------------------------------------------------------------------------------------ public void Save(string xliffFile) { var retry = true; for (;;) { try { XLiffXmlSerializationHelper.SerializeToFile(xliffFile, this); return; } catch (IOException) { if (retry) { // Maybe the file was locked. Wait and try again. retry = false; Thread.Sleep(20); } else { throw; } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reads the specified XLIFF file and returns a XLIFFDocument containing the information /// in the file. /// </summary> /// <param name= "xLiffFile">The XLiff file to read.</param> /// ------------------------------------------------------------------------------------ public static XLiffDocument Read(string xLiffFile) { if (!System.IO.File.Exists(xLiffFile)) { throw new FileNotFoundException("XLiff file not found.", xLiffFile); } Exception e; var xLiffDoc = XLiffXmlSerializationHelper.DeserializeFromFile <XLiffDocument>(xLiffFile, out e); if (e != null) { throw e; } // Fill in the fast lookup dictionary. var langId = xLiffDoc.File.TargetLang; if (string.IsNullOrEmpty(langId)) { langId = xLiffDoc.File.SourceLang; } foreach (var tu in xLiffDoc.File.Body.TransUnitsUnordered) { if (xLiffDoc.File.Body.TranslationsById.ContainsKey(tu.Id)) { Console.WriteLine("WARNING: string ID \"{0}\" already found in \"{1}\".", tu.Id, xLiffFile); } else if ((langId == xLiffDoc.File.SourceLang && langId == LocalizationManager.kDefaultLang) || !LocalizationManager.ReturnOnlyApprovedStrings || (tu.TranslationStatus == TranslationStatus.Approved)) { var target = tu.GetVariantForLang(langId); if (target != null && !string.IsNullOrEmpty(target.Value)) { xLiffDoc.File.Body.TranslationsById[tu.Id] = target.Value; } } } return(xLiffDoc); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Saves the XLIFFDocument to the specified XLIFF file. /// </summary> /// ------------------------------------------------------------------------------------ public void Save(string xliffFile) { XLiffXmlSerializationHelper.SerializeToFile(xliffFile, this); }