Exemplo n.º 1
0
        public void GenerateLangConfig()
        {
            if (KeyDictionary.Keys.Count < 1)
            {
                return;
            }
            List <string> itmes = new List <string>();

            foreach (var chinese in KeyDictionary.Keys)
            {
                var text = GetSingleItem(KeyDictionary[chinese],
                                         TransApi.GetTransResult(chinese, LangType.auto.ToString(), Type.ToString()));
                itmes.Add(text);
                itmes.Add("\r\n");
            }
            string itemtext = "";

            foreach (var itme in itmes)
            {
                itemtext += itme;
            }
            var        langFile   = GetLangFile(Node, itemtext);
            FileHelper fileHelper = new FileHelper();

            fileHelper.WriteFile("./LangFile/Resource.xml", langFile);
        }
Exemplo n.º 2
0
 public static string ToZh(string text)
 {
     if (string.IsNullOrEmpty(text))
     {
         throw new Exception("ToZh: text is null or empty");
     }
     lock (Lockobject)
     {
         var str = TransApi.GetTransResult(text, LangType.auto.ToString(), LangType.zh.ToString());
         return(string.IsNullOrWhiteSpace(str) ? text : str);
     }
 }
Exemplo n.º 3
0
 public static string Translate(string text, LangType langType = LangType.zh)
 {
     lock (Lockobject)
     {
         if (langType == LangType.zh)
         {
             return(text);
         }
         var    strArray = SplitStrings(text);
         string result   = string.Empty;
         foreach (var str in strArray)
         {
             result += TransApi.GetTransResult(str, LangType.auto.ToString(), langType.ToString());
         }
         return(string.IsNullOrWhiteSpace(result) ? text : result);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 获得翻译配置文件用的键值字典,返回的字典的键值是:需要翻译的文本,值是:查找文本所需要的键值
        /// </summary>
        /// <returns></returns>
        public virtual void GenerateKey()
        {
            Dictionary <string, string> keys = new Dictionary <string, string>();

            foreach (var value in ChineseDictionary.Values)
            {
                foreach (var str in value)
                {
                    if (keys.Keys.Contains(str))
                    {
                        continue;
                    }
                    //去掉双引号
                    var newstr = DeleteQuotes(str);
                    //选着前面两个文字
                    var towstr = newstr.Length > 2 ? newstr.Insert(2, "\0") : newstr;
                    //翻译生成键值
                    var key = TransApi.GetTransResult(towstr, LangType.auto.ToString(), LangType.en.ToString());
                    //添加到翻译文本和翻译结果的字典中
                    keys.Add(str, key);
                }
            }
            KeyDictionary = keys;
        }