Esempio n. 1
0
        /// <summary>
        /// Функция, предназначенная для распарсивания файла 'tmx'
        /// Translation Memory Exchange Format — Обмен памятью переводов
        /// </summary>
        /// <param name="fs">Поток tmx-файла миграции</param>
        public void Load(FileStream fs)
        {
            try
            {
                _logger.WriteLn("Распарсивание tmx-файла");
                //var tempFileName = Path.GetTempFileName();
                //fs.Seek(0, SeekOrigin.Begin);
                //fs.CopyTo(System.IO.File.Open(tempFileName, FileMode.Open));
                var tempFileName = tWriter.CopyFile(fs);
                var d            = XDocument.Load(tempFileName);
                var srclang      = d.Root.Element("header").Attribute("srclang");
                var body         = d.Root.Element("body");
                var ns_xml       = body.GetNamespaceOfPrefix("xml");
                foreach (var tu in body.Elements("tu"))
                {
                    Hashtable ht        = new Hashtable();
                    Guid?     newTermId = null;

                    foreach (var tuv in tu.Elements("tuv"))
                    {
                        var lang  = tuv.Attribute(ns_xml + "lang").Value;
                        var trans = tuv.Element("seg").Value;

                        tWriter.AppendTable(ht, lang, trans);
                        //newTermId = tWriter.AddTranslationSubstring(lang, ht, newTermId, memoryId, (Guid)memory.id_file);

                        try
                        {
                            TranslationSubstring termString =
                                tWriter.AddTranslationSubstring(lang, ht, newTermId, memoryId, (Guid)memory.id_file);
                            if (termString != null)
                            {
                                newTermId = ts.AddAsync(termString).Result;
                                gsr.AddTranslationMemoriesStrings((Guid)memoryId, (Guid)newTermId);
                                //newTermId = glossaryRep.AddNewTermAsync(memoryId, termString, null).Result;
                            }
                        }
                        catch (Exception exc)
                        {
                            _logger.WriteLn("ERROR: Перевод [" + trans + "] на язык [" + lang + "] " + exc.Message, exc);
                        }
                    }

                    foreach (var lang in ht.Keys)
                    {
                        tWriter.AddTranslation(lang, newTermId, ht);
                    }
                }


                System.IO.File.Delete(tempFileName);
                _logger.WriteLn("tmx-файл успешно распарсен");
            }
            catch (Exception ex)
            {
                _loggerError.WriteLn($"Ошибка в {typeof(TmxReader)}.{nameof(Load)}", ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Функция, предназначенная для распарсивания файла 'tbx'?
        /// Termbase Exchange format — Обмен терминологическими базами
        /// </summary>
        /// <param name="fs">Поток tbx-файла миграции</param>
        public void Load(FileStream fs)
        {
            try
            {
                _logger.WriteLn("Распарсивание tbx-файла");
                var tempFileName = tWriter.CopyFile(fs);

                var d  = XDocument.Load(tempFileName);
                var ns = d.Root.GetNamespaceOfPrefix("xml");
                foreach (var text in d.Root.Elements("text"))
                {
                    foreach (var termEntry in text.Element("body").Elements("termEntry"))
                    {
                        Hashtable ht        = new Hashtable();
                        Guid?     newTermId = null;
                        foreach (var langSet in termEntry.Elements("langSet"))
                        {
                            string lang = langSet.Attribute(ns + "lang").Value;
                            string term = langSet.Element("tig").Element("term").Value;
                            //ok, now it's all about where to write gathered data

                            tWriter.AppendTable(ht, lang, term);
                            TranslationSubstring termString = tWriter.AddTranslationSubstring(lang, ht, newTermId, glossaryId, (Guid)glossaries.ID_File);

                            if (termString != null)
                            {
                                newTermId = glossaryRep.AddNewTermAsync(glossaryId, termString, null).Result;
                            }
                        }

                        foreach (var lang in ht.Keys)
                        {
                            tWriter.AddTranslation(lang, newTermId, ht);
                        }
                        // break;
                    }
                }
                _logger.WriteLn("tbx-файл успешно распарсен");
                System.IO.File.Delete(tempFileName);

                /*
                 *
                 *
                 * INSERT INTO public.translation_substrings_locales
                 * (id_translation_substrings, id_locale)
                 * select id_string, id_locale
                 * from (
                 * select distinct t.id_string as id_string,  id_locale
                 * FROM public.translations as t) as tt
                 *
                 *
                 *
                 *
                 * INSERT INTO public.files_locales
                 * (id_file, id_locale,percent_of_confirmed, percent_of_translation)
                 * select 'd297766a-8d17-46f4-b8fc-be7e9165c66b', f. id_locale, 0,0
                 * from (select distinct  id_locale as id_locale
                 * FROM public.translations) as f
                 *
                 *
                 */
            }
            catch (Exception ex)
            {
                _loggerError.WriteLn($"Ошибка в {typeof(TbxReader)}.{nameof(Load)}", ex);
            }
        }