示例#1
0
        public override void Initialize(IInitializationContext context)
        {
            base.Initialize(context);

            MinDelay = context.GetOrCreateSetting("DeepL", "MinDelaySeconds", 2.0f);
            if (MinDelay < MinimumMinDelaySeconds)
            {
                XuaLogger.AutoTranslator.Warn($"[DeepL] Cannot set MinDelaySeconds below {MinimumMinDelaySeconds} second(s). Setting MinDelaySeconds={MinimumMinDelaySeconds}");
                context.SetSetting("DeepL", "MinDelaySeconds", MinimumMinDelaySeconds);
            }

            MaxDelay = context.GetOrCreateSetting("DeepL", "MaxDelaySeconds", 7.0f);
            if (MaxDelay < MinimumMaxDelaySeconds)
            {
                XuaLogger.AutoTranslator.Warn($"[DeepL] Cannot set MaxDelaySeconds below {MinimumMaxDelaySeconds} second(s). Setting MaxDelaySeconds={MinimumMaxDelaySeconds}");
                context.SetSetting("DeepL", "MaxDelaySeconds", MinimumMaxDelaySeconds);
            }

            if (!SupportedLanguages.Contains(FixLanguage(context.SourceLanguage)))
            {
                throw new EndpointInitializationException($"The source language '{context.SourceLanguage}' is not supported.");
            }
            if (!SupportedLanguages.Contains(FixLanguage(context.DestinationLanguage)))
            {
                throw new EndpointInitializationException($"The destination language '{context.DestinationLanguage}' is not supported.");
            }

            Arguments = Convert.ToBase64String(Encoding.UTF8.GetBytes("DeepLTranslate.ExtProtocol.ExtDeepLTranslate, DeepLTranslate.ExtProtocol"), Base64FormattingOptions.None);
        }
示例#2
0
        public override void Initialize(IInitializationContext context)
        {
            _appId     = context.GetOrCreateSetting("Baidu", "BaiduAppId", "");
            _appSecret = context.GetOrCreateSetting("Baidu", "BaiduAppSecret", "");
            _delay     = context.GetOrCreateSetting("Baidu", "DelaySeconds", 1.0f);
            if (string.IsNullOrEmpty(_appId))
            {
                throw new EndpointInitializationException("The BaiduTranslate endpoint requires an App Id which has not been provided.");
            }
            if (string.IsNullOrEmpty(_appSecret))
            {
                throw new EndpointInitializationException("The BaiduTranslate endpoint requires an App Secret which has not been provided.");
            }

            context.DisableCertificateChecksFor("api.fanyi.baidu.com");

            if (!SupportedLanguages.ContainsKey(FixLanguage(context.SourceLanguage)))
            {
                throw new EndpointInitializationException($"The source language '{context.SourceLanguage}' is not supported.");
            }
            if (!SupportedLanguages.ContainsKey(FixLanguage(context.DestinationLanguage)))
            {
                throw new EndpointInitializationException($"The destination language '{context.DestinationLanguage}' is not supported.");
            }
        }
        public override void Initialize(IInitializationContext context)
        {
            var backendOverride = context.GetOrCreateSetting <string>("GoogleV2", "ServiceUrl");

            if (!backendOverride.IsNullOrWhiteSpace())
            {
                _selectedUserBackend = backendOverride;

                _httpsServicePointTranslateTemplateUrl = _selectedUserBackend + HttpsServicePointTranslateTemplateUrl;

                XuaLogger.AutoTranslator.Info("The default backend for google translate was overwritten.");
            }
            else
            {
                _selectedUserBackend = DefaultUserBackend;

                _httpsServicePointTranslateTemplateUrl = _selectedUserBackend + HttpsServicePointTranslateTemplateUrl;
            }

            _translateRpcId        = context.GetOrCreateSetting("GoogleV2", "RPCID", "MkEWBc");
            _version               = context.GetOrCreateSetting("GoogleV2", "VERSION", "boq_translate-webserver_20210323.10_p0");
            _useSimplestSuggestion = context.GetOrCreateSetting("GoogleV2", "UseSimplest", false);


            context.DisableCertificateChecksFor(new Uri(_selectedUserBackend).Host, new Uri(_selectedUserBackend).Host);

            if (!SupportedLanguages.Contains(FixLanguage(context.SourceLanguage)))
            {
                throw new EndpointInitializationException($"The source language '{context.SourceLanguage}' is not supported.");
            }
            if (!SupportedLanguages.Contains(FixLanguage(context.DestinationLanguage)))
            {
                throw new EndpointInitializationException($"The destination language '{context.DestinationLanguage}' is not supported.");
            }
        }
        public override void Initialize(IInitializationContext context)
        {
            base.Initialize(context);

            if (!SupportedLanguages.Contains(FixLanguage(context.SourceLanguage)))
            {
                throw new EndpointInitializationException($"The source language '{context.SourceLanguage}' is not supported.");
            }
            if (!SupportedLanguages.Contains(FixLanguage(context.DestinationLanguage)))
            {
                throw new EndpointInitializationException($"The destination language '{context.DestinationLanguage}' is not supported.");
            }

            var apiKey = context.GetOrCreateSetting(ConfigurationSectionName, "ApiKey", "");
            var isFree = context.GetOrCreateSetting(ConfigurationSectionName, "Free", false);

            if (string.IsNullOrEmpty(apiKey))
            {
                throw new EndpointInitializationException($"The endpoint requires an API key which has not been provided.");
            }

            ConfigForExternalProcess = string.Join("\n", new[] { apiKey, isFree.ToString() });

            Arguments = Convert.ToBase64String(Encoding.UTF8.GetBytes("DeepLTranslate.ExtProtocol.ExtDeepLTranslateLegitimate, DeepLTranslate.ExtProtocol"), Base64FormattingOptions.None);
        }
示例#5
0
        public override void Initialize(IInitializationContext context)
        {
            var pathToLec = context.GetOrCreateSetting("LecPowerTranslator15", "InstallationPath", "");

            if (string.IsNullOrEmpty(pathToLec))
            {
                throw new Exception("The LecPowerTranslator15 requires the path to the installation folder.");
            }

            var exePath = Path.Combine(context.PluginDirectory, @"Translators\Lec.ExtProtocol.exe");

            var fileExists = File.Exists(exePath);

            if (!fileExists)
            {
                throw new Exception($"Could not find any executable at '{exePath}'");
            }

            ExecutablePath = exePath;
            Arguments      = Convert.ToBase64String(Encoding.UTF8.GetBytes(pathToLec));

            if (context.SourceLanguage != "ja")
            {
                throw new Exception("Current implementation only supports japanese-to-english.");
            }
            if (context.DestinationLanguage != "en")
            {
                throw new Exception("Current implementation only supports japanese-to-english.");
            }
        }
示例#6
0
        /// <summary>
        /// Called during initialization. Use this to initialize plugin or throw exception if impossible.
        ///
        /// Must set the ExecutablePath and optionally the Arguments property.
        /// </summary>
        public virtual void Initialize(IInitializationContext context)
        {
            _gameRoot = Paths.GameRoot;

            string exePath = null;

            if (ConfigurationSectionName != null)
            {
                exePath = context.GetOrCreateSetting <string>(ConfigurationSectionName, "ExecutableLocation", null);
            }

            if (string.IsNullOrEmpty(exePath))
            {
                exePath = Path.Combine(context.TranslatorDirectory, @"FullNET\Common.ExtProtocol.Executor.exe");
            }

            var fileExists = File.Exists(exePath);

            if (!fileExists)
            {
                throw new EndpointInitializationException($"Could not find any executable at '{exePath}'");
            }

            ExecutablePath = exePath;
        }
        public override void Initialize(IInitializationContext context)
        {
            var defaultPath = GetDefaultInstallationPath();
            var path        = context.GetOrCreateSetting("ezTrans", "InstallationPath", defaultPath);

            if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(defaultPath))
            {
                context.SetSetting("ezTrans", "InstallationPath", defaultPath);
                path = defaultPath;
            }

            //subprocess path
            var exePath = Path.Combine(context.TranslatorDirectory, @"FullNET\ezTransXP.ExtProtocol.exe");

            var fileExists = File.Exists(exePath);

            if (!fileExists)
            {
                throw new EndpointInitializationException($"Could not find any executable at '{exePath}'");
            }

            ExecutablePath = exePath;

            //argument is ezTrans installation path
            Arguments = Convert.ToBase64String(Encoding.UTF8.GetBytes(path));

            if (context.SourceLanguage != "ja")
            {
                throw new EndpointInitializationException("Current implementation only supports japanese-to-korean.");
            }
            if (context.DestinationLanguage != "ko")
            {
                throw new EndpointInitializationException("Current implementation only supports japanese-to-korean.");
            }
        }
示例#8
0
        public override void Initialize(IInitializationContext context)
        {
            _appId     = context.GetOrCreateSetting("Baidu", "BaiduAppId", "");
            _appSecret = context.GetOrCreateSetting("Baidu", "BaiduAppSecret", "");
            if (string.IsNullOrEmpty(_appId))
            {
                throw new ArgumentException("The BaiduTranslate endpoint requires an App Id which has not been provided.");
            }
            if (string.IsNullOrEmpty(_appSecret))
            {
                throw new ArgumentException("The BaiduTranslate endpoint requires an App Secret which has not been provided.");
            }

            context.DisableCertificateChecksFor("api.fanyi.baidu.com");

            // frankly, I have no idea what languages this does, or does not support...
        }
        public override void Initialize(IInitializationContext context)
        {
            _url = context.GetOrCreateSetting("Watson", "Url", "");
            _key = context.GetOrCreateSetting("Watson", "Key", "");
            if (string.IsNullOrEmpty(_url))
            {
                throw new EndpointInitializationException("The WatsonTranslate endpoint requires a url which has not been provided.");
            }
            if (string.IsNullOrEmpty(_key))
            {
                throw new EndpointInitializationException("The WatsonTranslate endpoint requires a key which has not been provided.");
            }

            _fullUrl = _url.TrimEnd('/') + "/v3/translate?version=2018-05-01";

            var model = FixLanguage(context.SourceLanguage) + "-" + FixLanguage(context.DestinationLanguage);

            if (!SupportedLanguagePairs.Contains(model))
            {
                throw new EndpointInitializationException($"The language model '{model}' is not supported.");
            }
        }
        public override void Initialize(IInitializationContext context)
        {
            _endpoint = context.GetOrCreateSetting("Custom", "Url", "");
            if (string.IsNullOrEmpty(_endpoint))
            {
                throw new EndpointInitializationException("The custom endpoint requires a url which has not been provided.");
            }

            var uri = new Uri(_endpoint);

            context.DisableCertificateChecksFor(uri.Host);

            _friendlyName += " (" + uri.Host + ")";
        }
示例#11
0
        public override void Initialize(IInitializationContext context)
        {
            _key = context.GetOrCreateSetting("Yandex", "YandexAPIKey", "");
            context.DisableCertificateChecksFor("translate.yandex.net");

            // if the plugin cannot be enabled, simply throw so the user cannot select the plugin
            if (string.IsNullOrEmpty(_key))
            {
                throw new Exception("The YandexTranslate endpoint requires an API key which has not been provided.");
            }
            if (!SupportedLanguages.Contains(context.SourceLanguage))
            {
                throw new Exception($"The source language '{context.SourceLanguage}' is not supported.");
            }
            if (!SupportedLanguages.Contains(context.DestinationLanguage))
            {
                throw new Exception($"The destination language '{context.DestinationLanguage}' is not supported.");
            }
        }
        public override void Initialize(IInitializationContext context)
        {
            if (context.DestinationLanguage == "romaji")
            {
                _translationsPerRequest = 1;
            }

            _selectedApiBackend  = DefaultApiBackend;
            _selectedUserBackend = DefaultUserBackend;

            var backendOverride = context.GetOrCreateSetting <string>("Google", "ServiceUrl");

            if (!backendOverride.IsNullOrWhiteSpace())
            {
                _selectedApiBackend  = backendOverride;
                _selectedUserBackend = backendOverride;

                _httpsServicePointTranslateTemplateUrl = _selectedApiBackend + HttpsServicePointTranslateTemplateUrl;
                _httpsServicePointRomanizeTemplateUrl  = _selectedApiBackend + HttpsServicePointRomanizeTemplateUrl;

                XuaLogger.AutoTranslator.Info("The default backend for google translate was overwritten.");
            }
            else
            {
                _selectedApiBackend  = DefaultApiBackend;
                _selectedUserBackend = DefaultUserBackend;

                _httpsServicePointTranslateTemplateUrl = _selectedApiBackend + HttpsServicePointTranslateTemplateUrl;
                _httpsServicePointRomanizeTemplateUrl  = _selectedApiBackend + HttpsServicePointRomanizeTemplateUrl;
            }

            context.DisableCertificateChecksFor(new Uri(_selectedApiBackend).Host, new Uri(_selectedUserBackend).Host);

            if (!SupportedLanguages.Contains(FixLanguage(context.SourceLanguage)))
            {
                throw new EndpointInitializationException($"The source language '{context.SourceLanguage}' is not supported.");
            }
            if (!SupportedLanguages.Contains(FixLanguage(context.DestinationLanguage)))
            {
                throw new EndpointInitializationException($"The destination language '{context.DestinationLanguage}' is not supported.");
            }
        }
        public override void Initialize(IInitializationContext context)
        {
            _key = context.GetOrCreateSetting("BingLegitimate", "OcpApimSubscriptionKey", "");
            if (string.IsNullOrEmpty(_key))
            {
                throw new EndpointInitializationException("The BingTranslateLegitimate endpoint requires an API key which has not been provided.");
            }

            // Configure service points / service point manager
            context.DisableCertificateChecksFor("api.cognitive.microsofttranslator.com");

            if (!SupportedLanguages.Contains(context.SourceLanguage))
            {
                throw new EndpointInitializationException($"The source language '{context.SourceLanguage}' is not supported.");
            }
            if (!SupportedLanguages.Contains(context.DestinationLanguage))
            {
                throw new EndpointInitializationException($"The destination language '{context.DestinationLanguage}' is not supported.");
            }
        }
        public override void Initialize(IInitializationContext context)
        {
            _key = context.GetOrCreateSetting("GoogleLegitimate", "GoogleAPIKey", "");
            if (string.IsNullOrEmpty(_key))
            {
                throw new Exception("The GoogleTranslateLegitimate endpoint requires an API key which has not been provided.");
            }

            // Configure service points / service point manager
            context.DisableCertificateChecksFor("translation.googleapis.com");

            if (!SupportedLanguages.Contains(context.SourceLanguage))
            {
                throw new Exception($"The source language '{context.SourceLanguage}' is not supported.");
            }
            if (!SupportedLanguages.Contains(context.DestinationLanguage))
            {
                throw new Exception($"The destination language '{context.DestinationLanguage}' is not supported.");
            }
        }
 public void Initialize(IInitializationContext context)
 {
     _myConfig = context.GetOrCreateSetting("Reverser", "MyConfig", true);
 }