/// <summary>Override; see base.</summary> protected override void CreateNewLanguage() { var newTranslation = TranslationCreateForm.CreateTranslation <TTranslation>(_moduleName, _settings.FontName, _settings.FontSize); if (newTranslation != null) { SetLanguage(newTranslation.Language); EditCurrentLanguage(); } }
/// <summary>Presents the user with a dialog to select a language from, and (if they click "OK") creates a new XML file for the new translation.</summary> /// <typeparam name="TTranslation">Class containing the translatable strings.</typeparam> /// <param name="moduleName">Name of the module being translated (forms part of the translation's XML file).</param> /// <param name="fontName">Specifies the name of the font to use in this dialog, or null for the default font.</param> /// <param name="fontSize">Specifies the size of the font to use in this dialog. Ignored if <paramref name="fontName"/> is null.</param> /// <returns>If the user clicked OK, creates a new XML file and returns the translation. If the user clicked Cancel, returns null.</returns> public static TTranslation CreateTranslation <TTranslation>(string moduleName, string fontName, float fontSize) where TTranslation : TranslationBase, new() { using (TranslationCreateForm tcf = new TranslationCreateForm()) { tcf.Font = fontName != null ? new Font(fontName, fontSize, FontStyle.Regular) : SystemFonts.MessageBoxFont; if (tcf.ShowDialog() != DialogResult.OK) { return(null); } if (tcf.SelectedLanguage == new TTranslation().Language) { DlgMessage.Show("This is the native language of the application. This translation cannot be edited, and you cannot create a new translation for this language.", "Error creating translation", DlgType.Error, "OK"); return(null); } var trans = new TTranslation { Language = tcf.SelectedLanguage }; string iso = trans.Language.GetIsoLanguageCode(); string xmlFile = PathUtil.AppPathCombine("Translations", moduleName + "." + iso + ".xml"); if (File.Exists(xmlFile)) { int result = DlgMessage.Show("A translation into the selected language already exists. If you wish to start this translation afresh, please delete the translation file first.\n\nThe translation file is: " + xmlFile, "Error creating translation", DlgType.Error, "&Go to containing folder", "Cancel"); if (result == 0) { Process.Start(Path.GetDirectoryName(xmlFile)); } return(null); } ClassifyXml.SerializeToFile(trans, xmlFile); return(trans); } }