private static void AddEnglishTerm(TmxFormat newTmx, Tu tmxTermEntry, string name) { if (!name.Contains("narrator")) { newTmx.Body.Tus.Add(tmxTermEntry); } }
public Tu Clone() { var clone = new Tu(Tuid); clone.Note = Note; if (Prop != null) { clone.Prop = Prop.Clone(); } foreach (var tuv in Tuvs) { clone.Tuvs.Add(new Tuv(tuv.Lang, tuv.LocalizedTerm)); } return(clone); }
private static List <Tu> ProcessLanguage(string modifiedLangAbbr, Action <TmxFormat, Tu, string> addTerm) { string outputFileName = Path.Combine(kLocalizationFolder, "Glyssen." + modifiedLangAbbr + ".tmx"); TmxFormat newTmx; if (File.Exists(outputFileName)) { newTmx = XmlSerializationHelper.DeserializeFromFile <TmxFormat>(outputFileName); var tus = newTmx.Body.Tus; // If this is not a language that has been worked on by a localizer, we can safely blow // away everything and start from scratch. Otherwise, we only want to remove translation units // which no longer exist in English. if (s_languagesWithCustomizedTranslations.Contains(modifiedLangAbbr)) { tus.RemoveAll(lt => lt.Tuid.StartsWith("CharacterName.") && !s_englishTranslationUnits.Any(ent => ent.Tuid == lt.Tuid)); } else { tus.RemoveAll(t => t.Tuid.StartsWith("CharacterName.")); } } else { newTmx = new TmxFormat(); newTmx.Header.SrcLang = modifiedLangAbbr; newTmx.Header.Props = new Prop[2]; newTmx.Header.Props[0] = new Prop("x-appversion", "0.17.0.0"); newTmx.Header.Props[1] = new Prop("x-hardlinebreakreplacement", "\\n"); } foreach (string name in s_names) { Tu tmxTermEntry = new Tu("CharacterName." + name) { Prop = new Prop("x-dynamic", "true") }; tmxTermEntry.Tuvs.Add(new Tuv("en", name)); addTerm(newTmx, tmxTermEntry, name); } XmlSerializationHelper.SerializeToFile(outputFileName, newTmx); return(newTmx.Body.Tus); }
private static void UpdateEntryWithLocalizedGloss(TmxFormat newTmx, Tu tmxTermEntry, Tuv newTuv) { var existingTranslationUnit = newTmx.Body.Tus.FirstOrDefault(t => t.Tuid == tmxTermEntry.Tuid); Tuv existingtuv = null; if (existingTranslationUnit != null) { existingtuv = existingTranslationUnit.Tuvs.FirstOrDefault(t => t.Lang == newTuv.Lang); } if (existingtuv != null) { if (s_processingUpdatedBiblicalTermsFiles && existingtuv.LocalizedTerm != newTuv.LocalizedTerm) { // Unless we're processing new updates to the Paratext Biblical Terms, any conflicts must come // from previous human localization work, so we'll just leave them as they are and not even bother // reporting them. TmxFormat paratextTmxFormat; if (!s_conflictingLocalizations.TryGetValue(newTuv.Lang, out paratextTmxFormat)) { s_conflictingLocalizations[newTuv.Lang] = paratextTmxFormat = new TmxFormat(newTmx); } paratextTmxFormat.Body.Tus.First((t => t.Tuid == tmxTermEntry.Tuid)) .Tuvs.First(t => t.Lang == newTuv.Lang) .LocalizedTerm = newTuv.LocalizedTerm; } } else { AddEntryWithLocalizedGloss(newTmx, tmxTermEntry, newTuv); TmxFormat conflictingTmx; if (s_processingUpdatedBiblicalTermsFiles && s_conflictingLocalizations.TryGetValue(newTuv.Lang, out conflictingTmx)) { conflictingTmx.Body.Tus.Add(tmxTermEntry.Clone()); } } }
private static void AddEntryWithLocalizedGloss(TmxFormat newTmx, Tu tmxTermEntry, Tuv newTuv) { tmxTermEntry.Tuvs.Add(newTuv); newTmx.Body.Tus.Add(tmxTermEntry); }
private static void AddLocalizedTerm(TmxFormat newTmx, string modifiedLangAbbr, BiblicalTermsLocalizations localTermsList, Tu tmxTermEntry, string name, Action <TmxFormat, Tu, Tuv> processLocalizedGloss) { // We only want to break a character ID into separate words for individual localization if it begins with a // proper name. int maxParts = Char.IsUpper(name[0]) ? Int32.MaxValue : 1; string[] parts = name.Split(new[] { ' ' }, maxParts, StringSplitOptions.RemoveEmptyEntries); string englishGloss = parts[0]; string endingPunct; if (Char.IsPunctuation(englishGloss.Last())) { endingPunct = englishGloss.Last().ToString(); englishGloss = englishGloss.Remove(englishGloss.Length - 1); } else { endingPunct = null; } Localization term = s_englishTermsList.Terms.Locals.Find(t => t.Gloss == englishGloss); if (term != null) { Localization localTerm = localTermsList.Terms.Locals.Find(t => t.Id == term.Id); if (localTerm != null) { string localGloss = s_partOfChineseOrFrenchGlossThatIsNotTheGloss.Replace(localTerm.Gloss, ""); if (localGloss != "") { if (endingPunct != null) { localGloss += endingPunct; } parts[0] = localGloss; if (parts.Length > 1) { for (int i = 1; i < parts.Length; i++) { englishGloss = parts[i]; bool openingParenthesis = false; if (englishGloss.StartsWith("(")) { englishGloss = englishGloss.Substring(1); openingParenthesis = true; } if (Char.IsPunctuation(englishGloss.Last())) { endingPunct = englishGloss.Last().ToString(); englishGloss = englishGloss.Remove(englishGloss.Length - 1); } else { endingPunct = null; } term = s_englishTermsList.Terms.Locals.Find(t => t.Gloss == englishGloss); if (term != null) { localTerm = localTermsList.Terms.Locals.Find(t => t.Id == term.Id); if (localTerm != null) { localGloss = s_partOfChineseOrFrenchGlossThatIsNotTheGloss.Replace(localTerm.Gloss, ""); if (localGloss != "") { if (openingParenthesis) { localGloss = "(" + localGloss; } if (endingPunct != null) { localGloss += endingPunct; } parts[i] = localGloss; continue; } } } parts[i] = "***" + parts[i] + "***"; } } var newTuv = new Tuv(modifiedLangAbbr, String.Join(" ", parts)); processLocalizedGloss(newTmx, tmxTermEntry, newTuv); } } } }