public void presentEstimateAndMakeOrder(TranslationConfigurationSO selectedConfig)
        {
            //var languageEstimates = new Dictionary<TransfluentLanguage, EstimateTranslationCostVO.Price>();
            if(_asyncFlow != null)
            {
                if(!_asyncFlow.orderIsDone())
                {
                    if(GUILayout.Button("ORDERING..."))
                    {
                    };
                    return;
                }
            }

            EstimateTranslationCostVO.Price costPerWordFromSourceLanguage = null;
            //Debug.Log("ASYNC FLOW:"+(_asyncFlow != null).ToString() + " isdone:"+(_asyncFlow != null && _asyncFlow.orderIsDone()));
            if(GUILayout.Button("Translate"))
            {
                doAuth();
                if(string.IsNullOrEmpty(_token))
                {
                    return;
                }

                string group = selectedConfig.translation_set_group;
                var sourceSet = GameTranslationGetter.GetTranslaitonSetFromLanguageCode(selectedConfig.sourceLanguage.code);
                if(sourceSet == null || sourceSet.getGroup(group) == null)
                {
                    EditorUtility.DisplayDialog("ERROR", "No messages in group", "OK");
                    return;
                }

                StringBuilder simpleEstimateString = new StringBuilder();

                //find the first language that returns a result for "hello" and use that for the cost
                foreach(TransfluentLanguage lang in selectedConfig.destinationLanguages)
                {
                    try
                    {
                        //TODO: other currencies
                        var call = new EstimateTranslationCost("hello", selectedConfig.sourceLanguage.id,
                                                            lang.id, quality: selectedConfig.QualityToRequest);
                        var callResult = doCall(call);
                        EstimateTranslationCostVO estimate = call.Parse(callResult.text);
                        //string printedEstimate = string.Format("Language:{0} cost per word: {1} {2}\n", lang.name, estimate.price.amount, estimate.price.currency);
                        costPerWordFromSourceLanguage = estimate.price;
                        //simpleEstimateString.Append(printedEstimate);
                        //Debug.Log("Estimate:" + JsonWriter.Serialize(estimate));
                        break;
                    }
                    catch(Exception e)
                    {
                        Debug.LogError("Error estimating prices: "+e);
                    }
                }

                var toTranslate = sourceSet.getGroup(group).getDictionaryCopy();
                long sourceSetWordCount = 0;
                foreach(KeyValuePair<string, string> kvp in toTranslate)
                {
                    sourceSetWordCount += kvp.Value.Split(' ').Length;
                }

                //var knownKeys = sourceSet.getPretranslatedKeys(sourceSet.getAllKeys(), selectedConfig.translation_set_group);
                //var sourceDictionary = sourceSet.getGroup().getDictionaryCopy();
                foreach(TransfluentLanguage lang in selectedConfig.destinationLanguages)
                {
                    if(lang.code == "xx-xx")
                    {
                        simpleEstimateString.AppendFormat("language: {0} est cost: {1}\n", lang.name, "FREE!");
                        continue;
                    }
                    var set = GameTranslationGetter.GetTranslaitonSetFromLanguageCode(lang.code);
                    long alreadyTranslatedWordCount = 0;

                    if(set != null)
                    {
                        var destKeys = set.getGroup(group).getDictionaryCopy();
                        foreach(KeyValuePair<string, string> kvp in toTranslate)
                        {
                            if(!destKeys.ContainsKey(kvp.Key))
                                alreadyTranslatedWordCount += kvp.Value.Split(' ').Length;
                        }
                    }

                    var oneWordPrice = costPerWordFromSourceLanguage;
                    float costPerWord = float.Parse(oneWordPrice.amount);
                    long toTranslateWordcount = sourceSetWordCount - alreadyTranslatedWordCount;
                    if(toTranslateWordcount < 0) toTranslateWordcount *= -1;

                    float totalCost = costPerWord * toTranslateWordcount;

                    simpleEstimateString.AppendFormat("language: {0} est cost: {1}\n", lang.name, totalCost);
                    //	lang.name, totalCost, oneWordPrice.currency, costPerWord, toTranslateWordcount);
                    //simpleEstimateString.AppendFormat("language name: {0} total cost: {1} {2} \n\tCost per word:{3} total words to translate:{4} ",
                    //	lang.name, totalCost, oneWordPrice.currency, costPerWord, toTranslateWordcount);
                }

                Debug.Log("Estimated prices");

                if(EditorUtility.DisplayDialog("Estimates", "Estimated cost(only additions counted in estimate):\n" + simpleEstimateString, "OK", "Cancel"))
                {
                    _asyncFlow = new OrderFlowAsync(selectedConfig, _token);
                    _asyncFlow.startFlow();
                    //doTranslation(selectedConfig);
                }
            }
        }
Esempio n. 2
0
        public void presentEstimateAndMakeOrder(TranslationConfigurationSO selectedConfig)
        {
            //var languageEstimates = new Dictionary<TransfluentLanguage, EstimateTranslationCostVO.Price>();
            if (_asyncFlow != null)
            {
                if (!_asyncFlow.orderIsDone())
                {
                    if (GUILayout.Button("ORDERING..."))
                    {
                    }
                    ;
                    return;
                }
            }

            EstimateTranslationCostVO.Price costPerWordFromSourceLanguage = null;
            //Debug.Log("ASYNC FLOW:"+(_asyncFlow != null).ToString() + " isdone:"+(_asyncFlow != null && _asyncFlow.orderIsDone()));
            if (GUILayout.Button("Translate"))
            {
                doAuth();
                if (string.IsNullOrEmpty(_token))
                {
                    return;
                }

                string group     = selectedConfig.translation_set_group;
                var    sourceSet = GameTranslationGetter.GetTranslaitonSetFromLanguageCode(selectedConfig.sourceLanguage.code);
                if (sourceSet == null || sourceSet.getGroup(group) == null)
                {
                    EditorUtility.DisplayDialog("ERROR", "No messages in group", "OK");
                    return;
                }

                StringBuilder simpleEstimateString = new StringBuilder();

                //find the first language that returns a result for "hello" and use that for the cost
                foreach (TransfluentLanguage lang in selectedConfig.destinationLanguages)
                {
                    try
                    {
                        //TODO: other currencies
                        var call = new EstimateTranslationCost("hello", selectedConfig.sourceLanguage.id,
                                                               lang.id, quality: selectedConfig.QualityToRequest);
                        var callResult = doCall(call);
                        EstimateTranslationCostVO estimate = call.Parse(callResult.text);
                        //string printedEstimate = string.Format("Language:{0} cost per word: {1} {2}\n", lang.name, estimate.price.amount, estimate.price.currency);
                        costPerWordFromSourceLanguage = estimate.price;
                        //simpleEstimateString.Append(printedEstimate);
                        //Debug.Log("Estimate:" + JsonWriter.Serialize(estimate));
                        break;
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("Error estimating prices: " + e);
                    }
                }

                var  toTranslate        = sourceSet.getGroup(group).getDictionaryCopy();
                long sourceSetWordCount = 0;
                foreach (KeyValuePair <string, string> kvp in toTranslate)
                {
                    sourceSetWordCount += kvp.Value.Split(' ').Length;
                }

                //var knownKeys = sourceSet.getPretranslatedKeys(sourceSet.getAllKeys(), selectedConfig.translation_set_group);
                //var sourceDictionary = sourceSet.getGroup().getDictionaryCopy();
                foreach (TransfluentLanguage lang in selectedConfig.destinationLanguages)
                {
                    if (lang.code == "xx-xx")
                    {
                        simpleEstimateString.AppendFormat("language: {0} est cost: {1}\n", lang.name, "FREE!");
                        continue;
                    }
                    var  set = GameTranslationGetter.GetTranslaitonSetFromLanguageCode(lang.code);
                    long alreadyTranslatedWordCount = 0;

                    if (set != null)
                    {
                        var destKeys = set.getGroup(group).getDictionaryCopy();
                        foreach (KeyValuePair <string, string> kvp in toTranslate)
                        {
                            if (!destKeys.ContainsKey(kvp.Key))
                            {
                                alreadyTranslatedWordCount += kvp.Value.Split(' ').Length;
                            }
                        }
                    }

                    var   oneWordPrice         = costPerWordFromSourceLanguage;
                    float costPerWord          = float.Parse(oneWordPrice.amount);
                    long  toTranslateWordcount = sourceSetWordCount - alreadyTranslatedWordCount;
                    if (toTranslateWordcount < 0)
                    {
                        toTranslateWordcount *= -1;
                    }

                    float totalCost = costPerWord * toTranslateWordcount;

                    simpleEstimateString.AppendFormat("language: {0} est cost: {1}\n", lang.name, totalCost);
                    //	lang.name, totalCost, oneWordPrice.currency, costPerWord, toTranslateWordcount);
                    //simpleEstimateString.AppendFormat("language name: {0} total cost: {1} {2} \n\tCost per word:{3} total words to translate:{4} ",
                    //	lang.name, totalCost, oneWordPrice.currency, costPerWord, toTranslateWordcount);
                }

                Debug.Log("Estimated prices");

                if (EditorUtility.DisplayDialog("Estimates", "Estimated cost(only additions counted in estimate):\n" + simpleEstimateString, "OK", "Cancel"))
                {
                    _asyncFlow = new OrderFlowAsync(selectedConfig, _token);
                    _asyncFlow.startFlow();
                    //doTranslation(selectedConfig);
                }
            }
        }
 public void doTranslation2(TranslationConfigurationSO selectedConfig)
 {
     OrderFlowAsync orderFlow = new OrderFlowAsync(selectedConfig, _token);
     orderFlow.startFlow();
 }
Esempio n. 4
0
        public void doTranslation2(TranslationConfigurationSO selectedConfig)
        {
            OrderFlowAsync orderFlow = new OrderFlowAsync(selectedConfig, _token);

            orderFlow.startFlow();
        }