示例#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
            }));
        }
示例#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, "保存成功"));
        }
示例#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));
        }
示例#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));
        }
示例#5
0
        public void Init()
        {
//			Debug.Log("book viewer init");
            _cameraZoom = gameObject.GetComponent <CameraZoom>();
            _cameraZoom.Init();

            _translateAgent = gameObject.GetComponent <TranslateAgent>();
            _translateAgent.Init();

            _defaultInput            = new InputObject();
            _defaultInput.horizontal = 0;
            _defaultInput.vertical   = 0;
            _defaultInput.depth      = 0;

            _input = _defaultInput;
        }
示例#6
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()));
        }
        /// <summary>
        /// Helper method to initiate the call that translate method.
        /// </summary>
        /// <param name="clientIdentity">The hawaii client identity.</param>
        /// <param name="text">The text to be translated.</param>
        /// <param name="to">The language translate to.</param>
        /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
        /// <param name="stateObject">Specifies a user-defined object.</param>
        /// <param name="from">The language translate from.</param>        
        private static void TranslateAsync(
           ClientIdentity clientIdentity,
           string text,
           string to,
           ServiceAgent<TranslateResult>.OnCompleteDelegate onComplete,
           object stateObject,
           string from = "")
        {
            TranslateAgent agent = new TranslateAgent(
                TranslatorService.HostName,
                clientIdentity,
                text,
                to,
                stateObject,
                from);

            agent.ProcessRequest(onComplete);
        }