コード例 #1
0
        private static void SaveTranslations(XML.StaticTexts fileContent, string fileDestination)
        {
            var serializer = new XmlSerializer(typeof(XML.StaticTexts));

            try
            {
                using (var writer = new StreamWriter(fileDestination))
                    serializer.Serialize(writer, fileContent);
            }
            catch (Exception ex)
            {
                Log.GravarLog(string.Format("Falha ao salvar o arquivo '{0}'. Erro: {1}. StackTrace: {2}", fileDestination, ex.Message, ex.StackTrace));
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            try
            {
                if (Languages.Count() == 0 || SourceFiles.Count() == 0 || DestPath == string.Empty)
                {
                    return;
                }

                var mergedTranslations = new List <XML.LocalizationGroup>();
                foreach (var language in Languages)
                {
                    var group = new XML.LocalizationGroup(language.Name);
                    foreach (string file in SourceFiles)
                    {
                        var originalFile = GetTranslations(file);
                        if (originalFile != null)
                        {
                            group.AddItems(originalFile);
                        }

                        var translatedFile = GetTranslations(Path.GetDirectoryName(file) + @"\" + Path.GetFileNameWithoutExtension(file) + GetSourceFileSeparator(file) + language.FileName + Path.GetExtension(file));
                        if (translatedFile != null)
                        {
                            group.AddItems(translatedFile);
                        }
                    }
                    mergedTranslations.Add(group);
                }

                var staticTexts = new XML.StaticTexts();
                staticTexts.Localization = mergedTranslations.ToArray();
                SaveTranslations(staticTexts, DestPath);
                Log.GravarLog(string.Format("Processamento XML concluído com sucesso. Arquivo de destino: '{0}'.", System.IO.Path.GetFullPath(DestPath)));
            }
            catch (Exception ex)
            {
                Log.GravarLog(string.Format("Ocorreu um erro no processamento do arquivo. Erro: {0}. StackTrace: {1}", ex.Message, ex.StackTrace));
            }
        }