Exemplo n.º 1
0
        /// <summary>
        /// 接收一批翻译任务
        /// </summary>
        /// <returns></returns>
        private Result AddNew()
        {
            string[] tasks = JsonConvert.DeserializeObject <string[]>(this.context.GetString());
            if (tasks == null || tasks.Length == 0)
            {
                return(new Result(false, "non-task"));
            }
            int           count       = 0;
            Regex         ignoreRegex = new Regex(@"~\d+~$");
            List <string> results     = new List <string>();

            foreach (string keyword in tasks)
            {
                if (ignoreRegex.IsMatch(keyword))
                {
                    continue;
                }
                if (TranslateAgent.Instance().AddKeyword(keyword, this.GetToken()))
                {
                    results.Add(keyword);
                    count++;
                }
            }
            return(new Result(true, this.GetToken(), new
            {
                count,
                Keyword = results
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <returns></returns>
        private Result Update()
        {
            string   id       = this.context.QF("ID");
            Language language = this.context.QF("Language").ToEnum <Language>();
            string   value    = this.context.QF("Value");

            TranslateAgent.Instance().SaveContent(id, language, value, this.GetToken());
            return(new Result(true, "保存成功"));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 在线翻译
        /// </summary>
        /// <returns></returns>
        private Result Online()
        {
            Language source  = this.context.QF("Source").ToEnum <Language>();
            Language target  = this.context.QF("Target").ToEnum <Language>();
            string   content = this.context.QF("Content");

            bool success = TranslateAgent.Instance().OnlineTranslate(source, target, content, out string message);

            return(new Result(success, message));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 当前的语言包配置文件
        /// </summary>
        /// <returns></returns>
        private Result Data()
        {
            TranslateModel model = new TranslateModel(this.context.GetParam("Language"))
            {
                Content = TranslateAgent.Instance().GetTranslate(this.GetToken())
            };

            if (this.context.GetParam("type") == "xml")
            {
                return(new Result(ContentType.XML, model.ToXml()));
            }
            return(new Result(true, this.GetToken(), model));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取语言包(数据库直接读取)
        /// </summary>
        /// <returns></returns>
        private Result TranslateData()
        {
            IEnumerable <string> contents = JsonConvert.DeserializeObject <string[]>(this.context.QF("Content")).Distinct();
            string token = this.GetToken();

            Language[] languages = this.context.QF("Language").Split(',').Select(t => t.ToEnum <Language>()).ToArray();
            //# Key存入Token
            foreach (string keyword in contents)
            {
                TranslateAgent.Instance().AddKeyword(keyword, token);
            }

            //# 获取目前数据库内的内容
            Dictionary <string, Dictionary <Language, string> > translates = new Dictionary <string, Dictionary <Language, string> >();

            foreach (string keyword in contents)
            {
                translates.Add(keyword, TranslateAgent.Instance().GetTranslate(keyword, languages));
            }

            return(new Result(ContentType.JSON, translates.ToJson()));
        }