public static IList<TranslationItemWithCategory> LoadNeutralItems() { Translation neutralTranslation = new Translation(); try { //Set language to neutral to get neutral translations GitCommands.Settings.CurrentTranslation = ""; List<Type> translatableTypes = TranslationUtl.GetTranslatableTypes(); foreach (Type type in translatableTypes) { ITranslate obj = TranslationUtl.CreateInstanceOfClass(type) as ITranslate; if (obj != null) obj.AddTranslationItems(neutralTranslation); } } finally { neutralTranslation.Sort(); //Restore translation GitCommands.Settings.CurrentTranslation = null; } IList<TranslationItemWithCategory> neutralItems = (from translationCategory in neutralTranslation.GetTranslationCategories() from translationItem in translationCategory.GetTranslationItems() select new TranslationItemWithCategory(translationCategory.Name, translationItem)).ToList(); return neutralItems; }
private void FillNeutralTranslation(Translation neutralTranslation) { try { //Set language to neutral to get neutral translations GitCommands.Settings.CurrentTranslation = ""; Translate(); List<Type> translatableTypes = TranslationUtl.GetTranslatableTypes(); foreach (Type type in translatableTypes) { ITranslate obj = CreateInstanceOfClass(type) as ITranslate; if (obj != null) obj.AddTranslationItems(neutralTranslation); } } finally { neutralTranslation.Sort(); //Restore translation GitCommands.Settings.CurrentTranslation = null; Translate(); } }
public static void AddTranslationItemsFromFields(string category, object obj, Translation translation) { if (obj == null) return; AddTranslationItemsFromList(category, translation, GetObjProperties(obj, "$this")); }
public static void Serialize(Translation translation, string path) { using (TextWriter tw = new StreamWriter(path, false)) { XmlSerializer serializer = new XmlSerializer(typeof(Translation)); serializer.Serialize(tw, translation); } }
public static void AddTranslationItemsFromList(string category, Translation translation, IEnumerable<Tuple<string, object>> items) { Action<string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo) { var value = (string)propertyInfo.GetValue(itemObj, null); if (AllowTranslateProperty(value)) translation.AddTranslationItem(category, item, propertyInfo.Name, value); }; ForEachItem(items, action); }
public Translator(string translationName) { if (string.IsNullOrEmpty(translationName)) { Translator.translation = null; } else if (!translationName.Equals(Translator.name)) { Translator.translation = TranslationSerializer.Deserialize(Translator.GetTranslationDir() + @"\" + translationName + ".xml"); } Translator.name = translationName; }
public void CreateInstanceOfClass() { List<Type> translatableTypes = TranslationUtl.GetTranslatableTypes(); Translation testTranslation = new Translation(); foreach (Type type in translatableTypes) { ITranslate obj = TranslationUtl.CreateInstanceOfClass(type) as ITranslate; obj.AddTranslationItems(testTranslation); obj.TranslateItems(testTranslation); } }
public static Translation GetTranslation(string translationName) { if (string.IsNullOrEmpty(translationName)) { Translator._translation = null; } else if (!translationName.Equals(Translator._name)) { Translator._translation = TranslationSerializer.Deserialize(Path.Combine(Translator.GetTranslationDir(), translationName + ".xml")); } Translator._name = translationName; return Translator._translation; }
public static void AddTranslationItemsFromFields(string category, object obj, Translation translation) { if (obj == null) return; Action<string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo) { var value = (string)propertyInfo.GetValue(itemObj, null); if (AllowTranslateProperty(value)) translation.AddTranslationItem(category, item, propertyInfo.Name, value); }; ForEachField(obj, action); }
public static Translation GetTranslation(string translationName) { if (string.IsNullOrEmpty(translationName)) { Translator._translation = null; } else if (!translationName.Equals(Translator._name)) { if (RunningOnWindows()) Translator._translation = TranslationSerializer.Deserialize(Translator.GetTranslationDir() + @"\" + translationName + ".xml"); else Translator._translation = TranslationSerializer.Deserialize(Translator.GetTranslationDir() + @"/" + translationName + ".xml"); } Translator._name = translationName; return Translator._translation; }
public void CreateInstanceOfClass() { // just reference to GitUI MouseWheelRedirector.Active = true; List<Type> translatableTypes = TranslationUtl.GetTranslatableTypes(); Translation testTranslation = new Translation(); foreach (Type type in translatableTypes) { ITranslate obj = TranslationUtl.CreateInstanceOfClass(type) as ITranslate; obj.AddTranslationItems(testTranslation); obj.TranslateItems(testTranslation); } }
public void CreateInstanceOfClass() { // just reference to GitUI MouseWheelRedirector.Active = true; List<Type> translatableTypes = TranslationUtl.GetTranslatableTypes(); ResourceManager.Translation.Translation testTranslation = new ResourceManager.Translation.Translation(); foreach (Type type in translatableTypes) { try { ITranslate obj = TranslationUtl.CreateInstanceOfClass(type) as ITranslate; obj.AddTranslationItems(testTranslation); obj.TranslateItems(testTranslation); } catch (System.Exception) { Trace.WriteLine("Problem with class: " + type.FullName); throw; } } }
public override void AddTranslationItems(Translation translation) { base.AddTranslationItems(translation); TranslationUtl.AddTranslationItemsFromFields(Name, _filterRevisionsHelper, translation); TranslationUtl.AddTranslationItemsFromFields(Name, _filterBranchHelper, translation); }
public static List<TranslationItemWithCategory> LoadTranslation(Translation translation, IEnumerable<TranslationItemWithCategory> neutralItems) { List<TranslationItemWithCategory> translateItems = new List<TranslationItemWithCategory>(); var oldTranslationItems = (from translationCategory in translation.GetTranslationCategories() from translationItem in translationCategory.GetTranslationItems() select new TranslationItemWithCategory(translationCategory.Name, translationItem)).ToList(); Dictionary<string, string> dict = new Dictionary<string, string>(); foreach (var item in neutralItems) { var curItem = (from trItem in oldTranslationItems where trItem.Category.TrimStart('_') == item.Category.TrimStart('_') && trItem.Name.TrimStart('_') == item.Name.TrimStart('_') && trItem.Property == item.Property select trItem).FirstOrDefault(); if (curItem == null) { curItem = item.Clone(); translateItems.Add(curItem); continue; } oldTranslationItems.Remove(curItem); curItem.Category = item.Category; curItem.Name = item.Name; if (curItem.Status == TranslationType.Translated || curItem.Status == TranslationType.Obsolete) { string source = curItem.NeutralValue ?? item.NeutralValue; if (!String.IsNullOrEmpty(curItem.TranslatedValue) && !dict.ContainsKey(source)) dict.Add(source, curItem.TranslatedValue); } if ((curItem.Status == TranslationType.Translated || curItem.Status == TranslationType.Obsolete) && !curItem.IsSourceEqual(item.NeutralValue)) curItem.Status = TranslationType.Unfinished; else if (curItem.Status == TranslationType.Obsolete && curItem.IsSourceEqual(item.NeutralValue)) curItem.Status = TranslationType.Translated; if (curItem.Status == TranslationType.Unfinished) { if (!String.IsNullOrEmpty(curItem.TranslatedValue) && curItem.OldNeutralValue == null && curItem.NeutralValue != item.NeutralValue) curItem.OldNeutralValue = curItem.NeutralValue; } else curItem.OldNeutralValue = null; curItem.NeutralValue = item.NeutralValue; translateItems.Add(curItem); } foreach (var item in oldTranslationItems) { if (String.IsNullOrEmpty(item.TranslatedValue)) continue; if ((item.Status == TranslationType.Translated || item.Status == TranslationType.Obsolete) && item.NeutralValue != null && !dict.ContainsKey(item.NeutralValue)) dict.Add(item.NeutralValue, item.TranslatedValue); item.Status = TranslationType.Obsolete; item.OldNeutralValue = null; translateItems.Add(item); } // update untranslated items var untranlatedItems = from trItem in translateItems where trItem.Status == TranslationType.New && dict.ContainsKey(trItem.NeutralValue) select trItem; foreach (var untranlatedItem in untranlatedItems) { untranlatedItem.TranslatedValue = dict[untranlatedItem.NeutralValue]; untranlatedItem.Status = TranslationType.Unfinished; } return translateItems; }
public static void SaveTranslation(string languageCode, IEnumerable<TranslationItemWithCategory> items, string filename) { Translation foreignTranslation = new Translation { GitExVersion = GitCommands.Settings.GitExtensionsVersionString, LanguageCode = languageCode }; foreach (TranslationItemWithCategory translateItem in items) { if (translateItem.Status == TranslationType.Obsolete && (String.IsNullOrEmpty(translateItem.TranslatedValue) || String.IsNullOrEmpty(translateItem.NeutralValue))) continue; TranslationItem ti = translateItem.GetTranslationItem().Clone(); if (ti.Status == TranslationType.New) ti.Status = TranslationType.Unfinished; Debug.Assert(!string.IsNullOrEmpty(ti.Value) || ti.Status != TranslationType.Translated); ti.Value = ti.Value ?? String.Empty; Debug.Assert(ti.Status != TranslationType.Translated || translateItem.IsSourceEqual(ti.Source)); foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).AddTranslationItem(ti); } TranslationSerializer.Serialize(foreignTranslation, filename); }
public virtual void AddTranslationItems(Translation translation) { TranslationUtl.AddTranslationItemsFromList("FormBrowse", translation, GetAdditionalMainMenuItemsForTranslation()); }
private void translations_SelectedIndexChanged(object sender, EventArgs e) { AskForSave(); changesMade = false; translation = Translator.GetTranslation(translations.Text); LoadTranslation(); FillTranslateGrid(translateCategories.SelectedItem as TranslationCategory); if (translation == null) { _NO_TRANSLATE_languageCode.Text = ""; return; } try { var culture = new CultureInfo(translation.LanguageCode); _NO_TRANSLATE_languageCode.Text = string.Concat(culture.TwoLetterISOLanguageName, " (", culture.DisplayName, ")"); } catch { _NO_TRANSLATE_languageCode.Text = translation.LanguageCode; } }
public static void TranslateItemsFromFields(string category, object obj, Translation translation) { if (obj == null) return; Action<string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo) { string value = translation.TranslateItem(category, item, propertyInfo.Name, null); if (value != null) propertyInfo.SetValue(itemObj, value, null); else if (propertyInfo.Name == "ToolTipText" && !String.IsNullOrEmpty((string)propertyInfo.GetValue(itemObj, null))) { value = translation.TranslateItem(category, item, "Text", null); if (value != null) propertyInfo.SetValue(itemObj, value, null); } }; ForEachField(obj, action); }
public virtual void TranslateItems(Translation translation) { Text = translation.TranslateItem(Name, "$this", "Text", Text); TranslationUtl.TranslateItemsFromFields(Name, this, translation); }
public virtual void AddTranslationItems(Translation translation) { if (!string.IsNullOrEmpty(Text)) translation.AddTranslationItem(Name, "$this", "Text", Text); TranslationUtl.AddTranslationItemsFromFields(Name, this, translation); }
public virtual void AddTranslationItems(Translation translation) { TranslationUtl.AddTranslationItemsFromFields(GetType().Name, this, translation); }
public virtual void TranslateItems(Translation translation) { TranslationUtl.TranslateItemsFromFields(Name, this, translation); }
public static void TranslateItemsFromList(string category, Translation translation, IEnumerable<Tuple<string, object>> items) { Action<string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo) { string value = translation.TranslateItem(category, item, propertyInfo.Name, null); if (!String.IsNullOrEmpty(value)) { if (propertyInfo.CanWrite) propertyInfo.SetValue(itemObj, value, null); } else if (propertyInfo.Name == "ToolTipText" && !String.IsNullOrEmpty((string)propertyInfo.GetValue(itemObj, null))) { value = translation.TranslateItem(category, item, "Text", null); if (!String.IsNullOrEmpty(value)) { if (propertyInfo.CanWrite) propertyInfo.SetValue(itemObj, value, null); } } }; ForEachItem(items, action); }
public virtual void TranslateItems(Translation translation) { TranslationUtl.TranslateItemsFromFields(ProxySwitcherFormName, this, translation); }
private void SaveAs() { var foreignTranslation = new Translation { LanguageCode = GetSelectedLanguageCode() }; if (foreignTranslation.LanguageCode != null) { foreach (TranslateItem translateItem in translate) { //Item is not translated (yet), skip it if (string.IsNullOrEmpty(translateItem.TranslatedValue)) continue; TranslationItem ti = new TranslationItem(translateItem.Name, translateItem.Property, translateItem.TranslatedValue); foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).AddTranslationItem(ti); } } else { // English language foreach (TranslateItem translateItem in translate) { TranslationItem ti = new TranslationItem(translateItem.Name, translateItem.Property, translateItem.NeutralValue); foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).AddTranslationItem(ti); } } var fileDialog = new SaveFileDialog { Title = saveAsText.Text, FileName = translations.Text + ".xml", Filter = saveAsTextFilter.Text + "|*.xml", DefaultExt = ".xml", AddExtension = true }; if (fileDialog.ShowDialog(this) == DialogResult.OK) { TranslationSerializer.Serialize(foreignTranslation, fileDialog.FileName); changesMade = false; } }
public override void TranslateItems(Translation translation) { base.TranslateItems(translation); TranslationUtl.TranslateItemsFromFields(FormBrowseName, filterRevisionsHelper, translation); TranslationUtl.TranslateItemsFromFields(FormBrowseName, filterBranchHelper, translation); }
public virtual void TranslateItems(Translation translation) { TranslationUtl.TranslateItemsFromFields(TranslationCategoryName, this, translation); TranslationUtl.TranslateItemsFromList(TranslationCategoryName, translation, GetMenuCommandsForTranslationImpl()); }
private void SaveAs() { var foreignTranslation = new Translation { LanguageCode = GetSelectedLanguageCode() }; foreach (TranslateItem translateItem in translate) { //Item is not translated (yet), skip it if (string.IsNullOrEmpty(translateItem.TranslatedValue)) continue; if (!foreignTranslation.HasTranslationCategory(translateItem.Category)) foreignTranslation.AddTranslationCategory(new TranslationCategory(translateItem.Category)); foreignTranslation.GetTranslationCategory(translateItem.Category).AddTranslationItem(new TranslationItem(translateItem.Name, translateItem.Property, translateItem.TranslatedValue)); } var fileDialog = new SaveFileDialog { Title = saveAsText.Text, FileName = translations.Text + ".xml" }; if (fileDialog.ShowDialog() == DialogResult.OK) { TranslationSerializer.Serialize(foreignTranslation, fileDialog.FileName); changesMade = false; } }
private void SaveAs() { var foreignTranslation = new Translation { GitExVersion = GitCommands.Settings.GitExtensionsVersionString, LanguageCode = GetSelectedLanguageCode() }; foreach (TranslateItem translateItem in translate) { string value = translateItem.TranslatedValue ?? String.Empty; TranslationItem ti = new TranslationItem(translateItem.Name, translateItem.Property, translateItem.NeutralValue, value); ti.Status = translateItem.Status; if (ti.Status == TranslationType.Obsolete && (String.IsNullOrEmpty(value) || String.IsNullOrEmpty(translateItem.NeutralValue))) continue; if (string.IsNullOrEmpty(value)) { if (ti.Status == TranslationType.Translated || ti.Status == TranslationType.New) ti.Status = TranslationType.Unfinished; } else { // TODO: Support in form if (ti.Status == TranslationType.Unfinished) ti.Status = TranslationType.Translated; } foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).AddTranslationItem(ti); } using (var fileDialog = new SaveFileDialog { Title = saveAsText.Text, FileName = translations.Text + ".xml", Filter = saveAsTextFilter.Text + "|*.xml", DefaultExt = ".xml", AddExtension = true }) { if (fileDialog.ShowDialog(this) == DialogResult.OK) { TranslationSerializer.Serialize(foreignTranslation, fileDialog.FileName); changesMade = false; } } }