Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
IsAppropriateForTranslate method obselete, CanBeTranslated implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
osoykan committed Jul 16, 2016
1 parent 9149c2d commit d37b2d1
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/DynamicTranslator.Bing/BingTranslatorFinder.cs
Expand Up @@ -35,7 +35,7 @@ public class BingTranslatorFinder : IMeanFinder

public async Task<TranslateResult> Find(TranslateRequest translateRequest)
{
if (!bingConfiguration.IsAppropriateForTranslation(translateRequest.FromLanguageExtension))
if (!bingConfiguration.CanBeTranslated())
return new TranslateResult(false, new Maybe<string>());

var requestObject = new
Expand Down
2 changes: 2 additions & 0 deletions src/DynamicTranslator.Bing/DynamicTranslatorBingModule.cs
@@ -1,13 +1,15 @@
using System.Reflection;

using Abp.Dependency;
using Abp.Modules;

using DynamicTranslator.Application;
using DynamicTranslator.Bing.Configuration;
using DynamicTranslator.LanguageManagement;

namespace DynamicTranslator.Bing
{
[DependsOn(typeof(DynamicTranslatorApplicationModule))]
public class DynamicTranslatorBingModule : DynamicTranslatorModule
{
public override void Initialize()
Expand Down
2 changes: 2 additions & 0 deletions src/DynamicTranslator.Google/DynamicTranslatorGoogleModule.cs
@@ -1,13 +1,15 @@
using System.Reflection;

using Abp.Dependency;
using Abp.Modules;

using DynamicTranslator.Application;
using DynamicTranslator.Google.Configuration;
using DynamicTranslator.LanguageManagement;

namespace DynamicTranslator.Google
{
[DependsOn(typeof(DynamicTranslatorApplicationModule))]
public class DynamicTranslatorGoogleModule : DynamicTranslatorModule
{
private const string GoogleTranslateUrl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl={0}&hl={1}&dt=t&dt=bd&dj=1&source=bubble&q={2}";
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicTranslator.Google/GoogleTranslateFinder.cs
Expand Up @@ -34,7 +34,7 @@ public class GoogleTranslateFinder : IMeanFinder

public async Task<TranslateResult> Find(TranslateRequest translateRequest)
{
if (!googleConfiguration.IsAppropriateForTranslation(translateRequest.FromLanguageExtension))
if (!googleConfiguration.CanBeTranslated())
return new TranslateResult(false, new Maybe<string>());

var uri = string.Format(
Expand Down
@@ -1,13 +1,15 @@
using System.Reflection;

using Abp.Dependency;
using Abp.Modules;

using DynamicTranslator.Application;
using DynamicTranslator.LanguageManagement;
using DynamicTranslator.SesliSozluk.Configuration;

namespace DynamicTranslator.SesliSozluk
{
[DependsOn(typeof(DynamicTranslatorApplicationModule))]
public class DynamicTranslatorSesliSozlukModule : DynamicTranslatorModule
{
public override void Initialize()
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicTranslator.SesliSozluk/SesliSozlukFinder.cs
Expand Up @@ -37,7 +37,7 @@ public class SesliSozlukFinder : IMeanFinder

public async Task<TranslateResult> Find(TranslateRequest translateRequest)
{
if (!sesliSozlukConfiguration.IsAppropriateForTranslation(translateRequest.FromLanguageExtension))
if (!sesliSozlukConfiguration.CanBeTranslated())
return new TranslateResult(false, new Maybe<string>());

var parameter =
Expand Down
Expand Up @@ -8,9 +8,9 @@ namespace DynamicTranslator.Tureng.Configuration
{
public class TurengTranslatorConfiguration : AbstractTranslatorConfiguration, ITurengTranslatorConfiguration
{
public override bool IsAppropriateForTranslation(string fromLanguageExtension)
public override bool CanBeTranslated()
{
return base.IsAppropriateForTranslation(fromLanguageExtension) && ApplicationConfiguration.IsToLanguageTurkish;
return base.CanBeTranslated() && ApplicationConfiguration.IsToLanguageTurkish;
}

public override IList<Language> SupportedLanguages { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/DynamicTranslator.Tureng/DynamicTranslatorTurengModule.cs
@@ -1,13 +1,15 @@
using System.Reflection;

using Abp.Dependency;
using Abp.Modules;

using DynamicTranslator.Application;
using DynamicTranslator.LanguageManagement;
using DynamicTranslator.Tureng.Configuration;

namespace DynamicTranslator.Tureng
{
[DependsOn(typeof(DynamicTranslatorApplicationModule))]
public class DynamicTranslatorTurengModule : DynamicTranslatorModule
{
public override void Initialize()
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicTranslator.Tureng/TurengFinder.cs
Expand Up @@ -29,7 +29,7 @@ public TurengFinder(IMeanOrganizerFactory meanOrganizerFactory, ITurengTranslato

public async Task<TranslateResult> Find(TranslateRequest translateRequest)
{
if (!turengConfiguration.IsAppropriateForTranslation(translateRequest.FromLanguageExtension))
if (!turengConfiguration.CanBeTranslated())
return new TranslateResult(false, new Maybe<string>());

var uri = new Uri(turengConfiguration.Url + translateRequest.CurrentText);
Expand Down
3 changes: 1 addition & 2 deletions src/DynamicTranslator.Wpf/DynamicTranslatorWpfModule.cs
Expand Up @@ -2,7 +2,6 @@

using Abp.Modules;

using DynamicTranslator.Application;
using DynamicTranslator.Bing;
using DynamicTranslator.Google;
using DynamicTranslator.SesliSozluk;
Expand All @@ -11,7 +10,7 @@

namespace DynamicTranslator.Wpf
{
[DependsOn(typeof(DynamicTranslatorApplicationModule),
[DependsOn(
typeof(DynamicTranslatorGoogleModule),
typeof(DynamicTranslatorYandexModule),
typeof(DynamicTranslatorBingModule),
Expand Down
2 changes: 2 additions & 0 deletions src/DynamicTranslator.Yandex/DynamicTranslatorYandexModule.cs
@@ -1,13 +1,15 @@
using System.Reflection;

using Abp.Dependency;
using Abp.Modules;

using DynamicTranslator.Application;
using DynamicTranslator.LanguageManagement;
using DynamicTranslator.Yandex.Configuration;

namespace DynamicTranslator.Yandex
{
[DependsOn(typeof(DynamicTranslatorApplicationModule))]
public class DynamicTranslatorYandexModule : DynamicTranslatorModule
{
private const string Url = "https://translate.yandex.net/api/v1.5/tr/translate?";
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicTranslator.Yandex/YandexFinder.cs
Expand Up @@ -28,7 +28,7 @@ public YandexFinder(IYandexTranslatorConfiguration configuration, IMeanOrganizer

public async Task<TranslateResult> Find(TranslateRequest translateRequest)
{
if (!configuration.IsAppropriateForTranslation(translateRequest.FromLanguageExtension))
if (!configuration.CanBeTranslated())
return new TranslateResult(false, new Maybe<string>());

var address = new Uri(
Expand Down
2 changes: 2 additions & 0 deletions src/DynamicTranslator.Zargan/DynamicTranslatorZarganModule.cs
@@ -1,13 +1,15 @@
using System.Reflection;

using Abp.Dependency;
using Abp.Modules;

using DynamicTranslator.Application;
using DynamicTranslator.LanguageManagement;
using DynamicTranslator.Zargan.Configuration;

namespace DynamicTranslator.Zargan
{
[DependsOn(typeof(DynamicTranslatorApplicationModule))]
public class DynamicTranslatorZarganModule : DynamicTranslatorModule
{
public override void Initialize()
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicTranslator.Zargan/ZarganFinder.cs
Expand Up @@ -26,7 +26,7 @@ public ZarganFinder(IZarganTranslatorConfiguration configuration, IMeanOrganizer

public async Task<TranslateResult> Find(TranslateRequest translateRequest)
{
if (!configuration.IsAppropriateForTranslation(translateRequest.FromLanguageExtension))
if (!configuration.CanBeTranslated())
return new TranslateResult(false, new Maybe<string>());

var uri = string.Format(configuration.Url, HttpUtility.UrlEncode(translateRequest.CurrentText, Encoding.UTF8));
Expand Down
Expand Up @@ -15,9 +15,9 @@ public abstract class AbstractTranslatorConfiguration : ITranslatorConfiguration

public IApplicationConfiguration ApplicationConfiguration { get; set; }

public virtual bool IsAppropriateForTranslation(string fromLanguageExtension)
public virtual bool CanBeTranslated()
{
return SupportedLanguages.Any(x => x.Extension == fromLanguageExtension)
return SupportedLanguages.Any(x => x.Extension == ApplicationConfiguration.ToLanguage.Extension)
&& ActiveTranslatorConfiguration.ActiveTranslators
.Any(x => x.Type == TranslatorType
&& x.IsActive
Expand Down
Expand Up @@ -6,6 +6,6 @@ public interface ITranslatorConfiguration : IMustHaveUrl, IMustHaveSupportedLang
{
TranslatorType TranslatorType { get; }

bool IsAppropriateForTranslation(string fromLanguageExtension);
bool CanBeTranslated();
}
}

0 comments on commit d37b2d1

Please sign in to comment.