コード例 #1
0
 /// <summary>
 /// Create a new file content
 /// </summary>
 public TranslationFileContent(TranslationFile file, String group)
 {
     if (file == null)
         throw new ArgumentNullException("file");
     this.File = file;
     this.Group = group;
     this.Content = new List<TranslationFileValue>();
 }
コード例 #2
0
 /// <summary>
 /// Create a new content
 /// </summary>
 public TranslationContent(String group, TranslationFile neutral, TranslationFile translations)
 {
     if (neutral == null)
         throw new ArgumentNullException("neutral");
     this.Group = group;
     this.Content = new List<TranslationContentValue>();
     this.NeutralFile = neutral;
     this.TranslationsFile = translations;
 }
コード例 #3
0
 /// <summary>
 /// Add a file in the group
 /// </summary>
 public TranslationFile AddFile(String file)
 {
     var tf = FindFile(file);
     if (tf == null)
     {
         tf = new TranslationFile(file);
         Files.Add(tf);
     }
     return tf;
 }
コード例 #4
0
 /// <summary>
 /// Read the translations from a translation file
 /// </summary>
 public static IEnumerable<TranslationFileValue> ReadFile(TranslationFile file, String group)
 {
     if (file == null) return null;
     if (String.Equals("dll", file.FileType, StringComparison.OrdinalIgnoreCase))
         return ReadExecutableFile(group ?? file.FileName, file.File);
     if (String.Equals("exe", file.FileType, StringComparison.OrdinalIgnoreCase))
         return ReadExecutableFile(group ?? file.FileName, file.File);
     if (String.Equals("resx", file.FileType, StringComparison.OrdinalIgnoreCase))
         return ReadResourceFile(group ?? file.FileName, file.File);
     if (String.Equals("xml", file.FileType, StringComparison.OrdinalIgnoreCase))
         return ReadXmlDocFile(file.File);
     throw new ArgumentException(Locales.SR.Error_CantReadFileType, file.FileType);
 }
 /// <summary>
 /// New translation file
 /// </summary>
 public TranslationFileViewModel(GroupViewModel group, TranslationFile file)
 {
     this.Group = group;
     this.File = file;
     if (this.File.IsNeutral)
     {
         this.Caption = Locales.SR.NeutralLanguageFile_Caption;
     }
     else
     {
         try
         {
             this.Culture = CultureInfo.GetCultureInfo(file.Language);
         }
         catch { }
         if (this.Culture == null)
             this.Caption = String.Format(Locales.SR.UnknownLanguageFile_Caption, this.File.Language);
         else
             this.Caption = this.Culture.DisplayName;
     }
 }
コード例 #6
0
 /// <summary>
 /// Load a content
 /// </summary>
 public static TranslationFileContent Load(TranslationFile file, String group)
 {
     TranslationFileContent content = new TranslationFileContent(file, group);
     content.LoadContent();
     return content;
 }
コード例 #7
0
 /// <summary>
 /// Scan for extensions translations
 /// </summary>
 int ScanForExtensionsInFolder(String folder)
 {
     int result = 0;
     if (!Directory.Exists(folder)) return result;
     // Search all .xml files with a .dll
     foreach (var dllFile in Directory.GetFiles(folder, "*.dll", SearchOption.TopDirectoryOnly))
     {
         var dllTf = new TranslationFile(dllFile);
         // Exclude known DLL
         if (String.Equals("SmallBasicLibrary", dllTf.FileName, StringComparison.OrdinalIgnoreCase))
             continue;
         // Check the the neutral XML file exists
         if (!File.Exists(dllFile.Substring(0, dllFile.Length - 4) + ".xml"))
             continue;
         // Search XML files for this DLL
         var files = Directory.GetFiles(folder, dllTf.FileName + "*.xml", SearchOption.TopDirectoryOnly);
         if (files.Length == 0) continue;
         // Find or create the extension group
         var group = FindOrCreateGroup(dllTf.FileName, String.Format(Locales.SR.TransGroup_Extension_Caption, dllTf.FileName));
         // Add files
         foreach (var file in files)
             group.AddFile(file);
         result++;
     }
     return result;
 }
コード例 #8
0
 /// <summary>
 /// Write the translations in a XmlDoc file
 /// </summary>
 public static void WriteXmlDocFile(TranslationFile file, IEnumerable<TranslationFileValue> translations)
 {
     XElement members = new XElement("members");
     XDocument xdoc = new XDocument(
         new XDeclaration("1.0", "UTF-8", null),
         new XElement("doc",
             new XElement("assembly", new XElement("name", file.FileName)),
             members
         )
         );
     foreach (var gTranslations in translations.GroupBy(m=>m.ReferenceGroup))
     {
         XElement member = new XElement("member", new XAttribute("name", gTranslations.Key));
         foreach (var trans in gTranslations)
         {
             XElement xtrans;
             var parts = trans.ReferenceCode.Split('@');
             try
             {
                 xtrans = XElement.Parse(String.Format("<{0}>{1}</{0}>", parts[0], trans.Translation));
             }
             catch {
                 xtrans = new XElement(parts[0], trans.Translation);
             }
             for (int i = 1; i < parts.Length; i++)
             {
                 var aparts = parts[1].Split(new char[] { ':' }, 2);
                 xtrans.Add(new XAttribute(aparts[0], aparts[1]));
             }
             member.Add(xtrans);
         }
         members.Add(member);
     }
     xdoc.Save(file.File);
 }
コード例 #9
0
 /// <summary>
 /// Write the translations in a resource file
 /// </summary>
 public static void WriteResourceFile(TranslationFile file, IEnumerable<TranslationFileValue> translations)
 {
     XDocument xdoc = XDocument.Parse(Properties.Resources.BaseXmlResourceFile);
     foreach (var trans in translations)
     {
         var xTrans = new XElement(
             "data",
             new XAttribute("name", trans.ReferenceCode),
             new XAttribute(XNamespace.Xml + "space", "preserve"),
             new XElement("value", trans.Translation)
             );
         if (!String.IsNullOrWhiteSpace(trans.Description))
             xTrans.Add(new XElement("comment", trans.Description));
         xdoc.Root.Add(xTrans);
     }
     xdoc.Save(file.File);
 }
コード例 #10
0
 /// <summary>
 /// Write the translation in a file
 /// </summary>
 public static bool WriteFile(TranslationFile file, String group, IEnumerable<TranslationFileValue> values, bool backupExistingFile)
 {
     if (file == null) return false;
     if (String.Equals("dll", file.FileType, StringComparison.OrdinalIgnoreCase))
         return false;
     if (String.Equals("exe", file.FileType, StringComparison.OrdinalIgnoreCase))
         return false;
     if (String.Equals("resx", file.FileType, StringComparison.OrdinalIgnoreCase))
     {
         if (backupExistingFile) BackupFile(file.File);
         WriteResourceFile(file, values);
         return true;
     }
     if (String.Equals("xml", file.FileType, StringComparison.OrdinalIgnoreCase))
     {
         if (backupExistingFile) BackupFile(file.File);
         WriteXmlDocFile(file, values);
         return true;
     }
     throw new ArgumentException(Locales.SR.Error_CantWriteFileType, file.FileType);
 }