Вход на сайт
Сохранение текстов на разных языках в базе данных
2187 просмотров
Перейти к просмотру всей ветки
в ответ uscheswoi_82 13.11.21 23:50, Последний раз изменено 14.11.21 02:17 (uscheswoi_82)
Так бы примерно бы делал бы:
using System; using System.IO; using System.Collections.Generic; using System.Text; namespace Backend { class Program { private static String Replace(String strTemplate, Dictionary<String, String> dicData) { StringBuilder stbData = new StringBuilder(strTemplate); foreach (KeyValuePair<String, String> item in dicData) stbData.Replace(item.Key, item.Value); return stbData.ToString(); } private static void Generate(String strTemplateFile, String strTemplateExpose, Dictionary<String, String> dicExposeItems, Dictionary<String, String> dicTemplateItems, String strOutput) { String strPath_expose = Directory.GetCurrentDirectory() + strTemplateExpose; String strPath_template = Directory.GetCurrentDirectory() + strTemplateFile; String strPath_output_html = Directory.GetCurrentDirectory() + strOutput; String strBuffer = File.ReadAllText(strPath_expose, Encoding.UTF8); String strBuffer2 = File.ReadAllText(strPath_template, Encoding.UTF8); dicTemplateItems.Remove("{content}"); dicTemplateItems.Add("{content}", Replace(strBuffer, dicExposeItems)); File.WriteAllText(strPath_output_html, Replace(strBuffer2, dicTemplateItems), Encoding.UTF8); } static void Main(string[] args) { String strLang = "en-us"; String strNow = DateTime.Now.ToString(); Dictionary<String, String> dicExposeItems = new Dictionary<string, string>(); dicExposeItems.Add("{InseratID}", "1"); dicExposeItems.Add("{CreateDate}", strNow); dicExposeItems.Add("{Title}", "House, 3 rooms"); dicExposeItems.Add("{CntRooms}", "3"); dicExposeItems.Add("{Description}", "House, 3 rooms"); dicExposeItems.Add("{Square}", "70"); Dictionary<String, String> dicTemplateItems = new Dictionary<string, string>(); dicTemplateItems.Add("{lang}", "en"); dicTemplateItems.Add("{title}", "House, 3 rooms"); Generate(String.Format(@"\template.{0}.xml", strLang), String.Format(@"\expose.{0}.xml", strLang), dicExposeItems, dicTemplateItems, String.Format(@"\demo.{0}.html", strLang)); strLang = "ru-ru"; dicTemplateItems.Remove("{lang}"); dicTemplateItems.Add("{lang}", strLang.Substring(0, 2)); Generate(String.Format(@"\template.{0}.xml", strLang), String.Format(@"\expose.{0}.xml", strLang), dicExposeItems, dicTemplateItems, String.Format(@"\demo.{0}.html", strLang)); strLang = "de-de"; dicTemplateItems.Remove("{lang}"); dicTemplateItems.Add("{lang}", strLang.Substring(0, 2)); Generate(String.Format(@"\template.{0}.xml", strLang), String.Format(@"\expose.{0}.xml", strLang), dicExposeItems, dicTemplateItems, String.Format(@"\demo.{0}.html", strLang)); } } }
Результат см.:https://i.ibb.co/Z1stvX4/r-min.jpg
Если я кому-то отвечаю, это не значит что я ему симпатизирую, каждый остаётся при своём мнение