import { Component , Inject , OnInit } from '@angular/core' ; import { TinyTranslatorService } from '../model/tiny-translator.service' ; import { Observable } from 'rxjs/Observable' ; const TEST_MESSAGE = 'Hello world!' ; @ Component ( { selector : 'app-configure-auto-translate-page' , templateUrl : './configure-auto-translate-page.component.html' , styleUrls : [ './configure-auto-translate-page.component.css' ] } ) export class ConfigureAutoTranslatePageComponent implements OnInit { apiKey : string ; _sourceLanguage : string ; _targetLanguage : string ; _sourceLanguageTest : string ; _targetLanguageTest : string ; testCallSourceResult : string ; testCallTargetResult : string ; constructor ( private translatorService ) { if ( this . translatorService . currentProject ( ) && this . translatorService . currentProject ( ) . canTranslate ( ) ) { this . _sourceLanguage = this . translatorService . currentProject ( ) . translationFile . sourceLanguage ( ) ; this . _targetLanguage = this . translatorService . currentProject ( ) . translationFile . targetLanguage ( ) ; } this . _sourceLanguageTest = 'en' ; this . _targetLanguageTest = 'de' ; } ngOnInit ( ) { this . apiKey = this . translatorService . autoTranslateApiKey ( ) ; } autoTranslateDisabled ( ) { return this . translatorService . canAutoTranslate ( ) . map ( ( val ) => ! val ) ; } autoTranslateDisabledReason ( ) { return this . translatorService . autoTranslateDisabledReason ( ) ; } sourceLanguage ( ) { return this . _sourceLanguage ; } targetLanguage ( ) { return this . _targetLanguage ; } autoTranslateDisabledTest ( ) { return this . translatorService . canAutoTranslateForLanguages ( this . _sourceLanguageTest , this . _targetLanguageTest ) . map ( ( val ) => ! val ) ; } autoTranslateDisabledReasonTest ( ) { return this . translatorService . autoTranslateDisabledReasonForLanguages ( this . _sourceLanguageTest , this . _targetLanguageTest ) ; } sourceLanguageTest ( ) { return this . _sourceLanguageTest ; } targetLanguageTest ( ) { return this . _targetLanguageTest ; } setApiKey ( ) { this . translatorService . setAutoTranslateApiKey ( this . apiKey ) ; } testCall ( ) { this . testCallSourceResult = null ; this . testCallTargetResult = null ; if ( this . _sourceLanguageTest !== 'en' ) { this . translatorService . testAutoTranslate ( TEST_MESSAGE , 'en' , this . _sourceLanguageTest ) . subscribe ( ( translationToSource ) => { this . testCallSourceResult = translationToSource ; this . translatorService . testAutoTranslate ( translationToSource , this . _sourceLanguageTest , this . _targetLanguageTest ) . subscribe ( ( translationToTarget ) => { this . testCallTargetResult = translationToTarget ; } ) ; } ) ; } else { this . testCallSourceResult = TEST_MESSAGE ; this . translatorService . testAutoTranslate ( this . testCallSourceResult , this . _sourceLanguageTest , this . _targetLanguageTest ) . subscribe ( ( translationToTarget ) => { this . testCallTargetResult = translationToTarget ; } ) ; } } }