コード例 #1
0
ファイル: XLiffDocument.cs プロジェクト: gmartin7/l10nsharp
        /// ------------------------------------------------------------------------------------
        /// <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;
                    }
                }
            }
        }
コード例 #2
0
ファイル: XLiffDocument.cs プロジェクト: gmartin7/l10nsharp
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
コード例 #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Saves the XLIFFDocument to the specified XLIFF file.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void Save(string xliffFile)
 {
     XLiffXmlSerializationHelper.SerializeToFile(xliffFile, this);
 }