/// ------------------------------------------------------------------------------------ internal TransUnitUpdater(TMXDocument tmxDoc) { _tmxDoc = tmxDoc; var replacement = _tmxDoc.Header.GetPropValue(LocalizedStringCache.kHardLineBreakReplacementProperty); if (replacement != null) { _literalNewline = replacement; } }
private static void MakeEnglishTmxWithApparentOrphan(TempFolder folder) { var englishDoc = new TMXDocument { Header = { SourceLang = "en" } }; englishDoc.Header.SetPropValue(LocalizationManager.kAppVersionPropTag, LowerVersion); englishDoc.AddTransUnit(MakeTransUnit("en", null, "Title", "SuperClassMethod.TestId", false)); // This is the one ID found in our test code englishDoc.AddTransUnit(MakeTransUnit("en", null, "Title", "AnotherContext.AnotherDialog.TestId", true)); // Simulates an 'orphan' that we can't otherwise tell we need. Directory.CreateDirectory(GetInstalledDirectory(folder)); englishDoc.Save(Path.Combine(GetInstalledDirectory(folder), LocalizationManager.GetTmxFileNameForLanguage(AppId, "en"))); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates an empty string file. /// </summary> /// ------------------------------------------------------------------------------------ internal static TMXDocument CreateEmptyStringFile() { var tmxDoc = new TMXDocument(); tmxDoc.Header.CreationTool = "Palaso Localization Manager"; tmxDoc.Header.CreationToolVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); tmxDoc.Header.SourceLang = LocalizationManager.kDefaultLang; tmxDoc.Header.AddProp(LocalizationManager.kAppVersionPropTag, "0.0.0"); tmxDoc.Header.AddProp(kHardLineBreakReplacementProperty, s_literalNewline); //tmxDoc.Header.AddProp(kHardLineBreakReplacementProperty, s_literalNewline);//REVIEW: why is this listed twice? I notice that there is no ampersand replacement policy: was this line meant to be for that? return(tmxDoc); }
private static void MakeArabicTmxWithApparentOrphans(TempFolder folder, string englishForObsoleteTitle) { var arabicDoc = new TMXDocument { Header = { SourceLang = "ar" } }; arabicDoc.Header.SetPropValue(LocalizationManager.kAppVersionPropTag, LowerVersion); // Note that we do NOT have arabic for SuperClassMethod.TestId. We may end up getting a translation from the orphan, however. arabicDoc.AddTransUnit(MakeTransUnit("ar", "Title", "Title in Arabic", "AnotherContext.AnotherDialog.TestId", true)); // Not an orphan, because English TMX has this too // Interpreted as an orphan iff englishForObsoleteTitle is "Title" (matching the English for SuperClassMethod.TestId) arabicDoc.AddTransUnit(MakeTransUnit("ar", englishForObsoleteTitle, "Title in Arabic", "AnObsoleteNameForSuperclass.TestId", true)); Directory.CreateDirectory(GetInstalledDirectory(folder)); arabicDoc.Save(Path.Combine(GetInstalledDirectory(folder), LocalizationManager.GetTmxFileNameForLanguage(AppId, "ar"))); }
private static void AddArabicTmx(string folderPath) { var arabicDoc = new TMXDocument { Header = { SourceLang = "ar" } }; // first unit var variants = new List <TransUnitVariant> { new TransUnitVariant { Lang = "en", Value = "wrong" }, new TransUnitVariant { Lang = "ar", Value = "inArabic" } }; var tu = new TransUnit { Id = "theId", Variants = variants }; tu.AddProp("ar", LocalizedStringCache.kDiscoveredDyanmically, "true"); tu.AddProp("en", LocalizedStringCache.kDiscoveredDyanmically, "true"); arabicDoc.AddTransUnit(tu); // second unit var variants2 = new List <TransUnitVariant> { new TransUnitVariant { Lang = "en", Value = "inEnglishpartofArabicTMX" }, new TransUnitVariant { Lang = "ar", Value = "inArabic" } }; var tu2 = new TransUnit { Id = "notUsedId", Variants = variants2 }; tu2.AddProp("ar", LocalizedStringCache.kDiscoveredDyanmically, "true"); tu2.AddProp("en", LocalizedStringCache.kDiscoveredDyanmically, "true"); // Note: we are NOT adding a NoLongerUsed property to the Arabic TMX arabicDoc.AddTransUnit(tu2); arabicDoc.Save(Path.Combine(folderPath, LocalizationManager.GetTmxFileNameForLanguage(AppId, "ar"))); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Loads the string cache from all the specified tmx files /// </summary> /// ------------------------------------------------------------------------------------ internal LocalizedStringCache(LocalizationManager owningManager) { OwningManager = owningManager; TmxDocument = CreateEmptyStringFile(); _englishTuIdsNoLongerUsed = new HashSet <string>(); try { MergeTmxFilesIntoCache(OwningManager.TmxFilenamesToAddToCache); } catch (Exception e) { MessageBox.Show("Error occurred reading localization file:" + Environment.NewLine + e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); LocalizationManager.SetUILanguage(LocalizationManager.kDefaultLang, false); } _tuUpdater = new TransUnitUpdater(TmxDocument); var replacement = TmxDocument.Header.GetPropValue("x-ampersandreplacement"); if (replacement != null) { _ampersandReplacement = replacement; } replacement = TmxDocument.Header.GetPropValue(kHardLineBreakReplacementProperty); if (replacement != null) { s_literalNewline = replacement; } LeafNodeList = new List <LocTreeNode>(); IsDirty = false; }
/// ------------------------------------------------------------------------------------ private void MergeTmxFilesIntoCache(IEnumerable <string> tmxFiles) { var defaultTmxDoc = TMXDocument.Read(OwningManager.DefaultStringFilePath); foreach (var tu in defaultTmxDoc.Body.TransUnits) { TmxDocument.Body.AddTransUnit(tu); // If this TransUnit is marked NoLongerUsed in the English tmx, load its ID into the hashset // so we don't display this string in case the currentUI tmx doesn't have it marked as // NoLongerUsed. if (tu.GetPropValue(kNoLongerUsedPropTag) != null) { _englishTuIdsNoLongerUsed.Add(tu.Id); } } // It's possible (I think when there is no customizable TMX, as on first install, but the version in the installed TMX // is out of date with the app) that we don't have all the info from the installed TMX in the customizable one. // We want to make sure that (a) any new dynamic strings in the installed one are considered valid by default // (b) any newly obsolete IDs are noted. if (File.Exists(OwningManager.DefaultInstalledStringFilePath)) { var defaultInstalledTmxDoc = TMXDocument.Read(OwningManager.DefaultInstalledStringFilePath); foreach (var tu in defaultInstalledTmxDoc.Body.TransUnits) { TmxDocument.Body.AddTransUnitOrVariantFromExisting(tu, "en"); // also needed in this, to prevent things we find here from being considered orphans. defaultTmxDoc.Body.AddTransUnitOrVariantFromExisting(tu, "en"); // If this TransUnit is marked NoLongerUsed in the English tmx, load its ID into the hashset // so we don't display this string in case the currentUI tmx doesn't have it marked as // NoLongerUsed. if (tu.GetPropValue(kNoLongerUsedPropTag) != null) { _englishTuIdsNoLongerUsed.Add(tu.Id); } } } Exception error = null; var stillNeedToLoadNoLongerUsed = _englishTuIdsNoLongerUsed.Count == 0; foreach (var file in tmxFiles.Where(f => Path.GetFileName(f) != OwningManager.DefaultStringFilePath)) { try { var tmxDoc = TMXDocument.Read(file); var langId = tmxDoc.Header.SourceLang; foreach (var tu in tmxDoc.Body.TransUnits) { // This block attempts to find 'orphans', that is, localizations that have been done using an obsolete ID. // We assume the default language TMX has only current IDs, and therefore don't look for orphans in that case. // This guards against cases such as recently occurred in Bloom, where a dynamic ID EditTab.AddPageDialog.Title // was regarded as an obsolete id for PublishTab.Upload.Title if (langId != LocalizationManager.kDefaultLang && defaultTmxDoc.GetTransUnitForId(tu.Id) == null && !tu.Id.EndsWith(kToolTipSuffix) && !tu.Id.EndsWith(kShortcutSuffix)) { //if we couldn't find it, maybe the id just changed and then if so re-id it. var movedUnit = defaultTmxDoc.GetTransUnitForOrphan(tu); if (movedUnit == null) { if (tu.GetPropValue(kDiscoveredDyanmically) == "true") { //ok, no big deal, that what we expect with dynamic strings, by definition... that we won't find them during a static code scan } else { tu.AddProp(kNoLongerUsedPropTag, "true"); } } else { tu.Id = movedUnit.Id; } } TmxDocument.Body.AddTransUnitOrVariantFromExisting(tu, langId); if (stillNeedToLoadNoLongerUsed && langId == LocalizationManager.kDefaultLang && tu.GetPropValue(kNoLongerUsedPropTag) != null) { _englishTuIdsNoLongerUsed.Add(tu.Id); } } } catch (Exception e) { #if DEBUG throw e; #else //REVIEW: Better explain the conditions where we get an error on a file but don't care about it? // If error happened reading some localization file other than the one we care // about right now, just ignore it. if (file == OwningManager.GetTmxPathForLanguage(LocalizationManager.UILanguageId, false)) { error = e; } #endif } } if (error != null) { throw error; } }