public void AddTranslationItemIfNotExist(TranslationItem translationItem) { if (string.IsNullOrEmpty(translationItem.Name)) { throw new InvalidOperationException("Cannot add translationitem without name"); } TranslationItem ti = GetTranslationItem(translationItem.Name, translationItem.Property); if (ti == null) { if (translationItem.Property == "ToolTipText") { ti = GetTranslationItem(translationItem.Name, "Text"); if (ti == null || translationItem.Value != ti.Value) { TranslationItems.Add(translationItem); } } else { TranslationItems.Add(translationItem); } } else { Debug.Assert(ti.Value == translationItem.Value, "ti.Value == translationItem.Value"); } }
public void AddTranslationItemIfNotExist(TranslationItem translationItem) { if (GitExtUtils.Strings.IsNullOrEmpty(translationItem.Name)) { throw new InvalidOperationException($"Cannot add {nameof(TranslationItem)} without name"); } TranslationItem?ti = GetTranslationItem(translationItem.Name, translationItem.Property); if (ti is null) { if (translationItem.Property == "ToolTipText") { ti = GetTranslationItem(translationItem.Name, "Text"); if (ti is null || translationItem.Source != ti.Source) { TranslationItems.Add(translationItem); } } else { TranslationItems.Add(translationItem); } } else { Debug.Assert(ti.Value == translationItem.Value, "ti.Value == translationItem.Value"); } }
public void AddTranslationItem(TranslationItem translationItem) { if (string.IsNullOrEmpty(translationItem.Name)) { throw new InvalidOperationException("Cannot add translationitem without name"); } TranslationItems.Add(translationItem); }
public string TranslateItem(string category, string item, string property, string defaultValue) { TranslationCategory tc = GetTranslationCategory(category); if (tc == null) { return(defaultValue); } TranslationItem ti = tc.Body.GetTranslationItem(item, property); return(ti == null || string.IsNullOrEmpty(ti.Value) ? defaultValue : ti.Value); }
public string TranslateItem(string category, string item, string property, Func <string> provideDefaultValue) { TranslationCategory tc = FindOrAddTranslationCategory(category); TranslationItem ti = tc.Body.GetTranslationItem(item, property); if (ti == null) { // if an item is not translated, then store its default value // to be able to retrieve it later (eg. when to a caption // is added an additional information like 'Commit (<number of changes>)', // and then the caption needs to be refreshed) string defaultValue = provideDefaultValue(); tc.Body.AddTranslationItemIfNotExist(new TranslationItem(item, property, defaultValue)); return(defaultValue); } if (string.IsNullOrEmpty(ti.Value)) { return(ti.Source); } return(ti.Value); }