import { translateContainer } from "./translate-container" ; import { getKeyName } from '../functions/get-key-name' ; import { MultiLingualData } from '../core/multilingual-data' ; import { BaseResolver } from '../resolver/base-resolver' ; import { translateConfigContainer } from '../core/translate-config-container' ; import { HttpClient } from "@angular/common/http" ; import { Injectable } from "@angular/core" ; import { ErrorMessageConfig } from "../interface/error-message-config" ; import { overrideErrorsProperty } from "../functions/override-errors-property" ; @ Injectable ( ) export class TranslationResolver { constructor ( private httpClient ) { } private _allowedLanguages : Array < string > = [ ] ; set controlErrorMessage ( value ) { if ( translateConfigContainer . config && ! translateConfigContainer . config . controlErrorMessage ) { translateConfigContainer . config . controlErrorMessage = value ; overrideErrorsProperty ( translateConfigContainer . config . controlErrorMessage ) ; } } set resolver ( value ) { translateConfigContainer . resolver = value ; } get allowedLanguages ( ) { return this . _allowedLanguages ; } get activeTranslationsLength ( ) { return translateContainer . getActiveTranslations ( ) . length ; } set ngxTranslate ( value ) { translateConfigContainer . ngxTranslate = value ; translateConfigContainer . customLoader = value . customLoader ; } get injector ( ) { return translateConfigContainer . injector ; } get pending ( ) { return translateConfigContainer . loading ; } get activeLanguage ( ) { return translateConfigContainer . config . languageCode ; } set activeLanguage ( lang ) { translateConfigContainer . config . languageCode = lang ; } get translations ( ) { return MultiLingualData . data ; } getTranslationName ( nodeName , languageCode = null ) { let instance = translateContainer . getComponentState ( nodeName ) ; if ( instance ) { let translateConfig = translateContainer . get ( instance ) ; if ( translateConfig && translateConfig . config ) return getKeyName ( translateConfig . config . translationName , languageCode ) ; } return null ; } getTranslationNameByInstance ( instance , languageCode = null ) { let translateConfig = translateContainer . get ( instance ) ; if ( translateConfig && translateConfig . config ) return getKeyName ( translateConfig . config . translationName , languageCode ) ; return null ; } get ( modelName , languageCode = '' ) { return MultiLingualData . get ( this . getKeyName ( modelName , languageCode ) ) ; } getKeyName ( modelName , languageCode = '' ) { return getKeyName ( modelName , languageCode ) ; } resolve ( modelName , languageCode ) { var baseResolver = new BaseResolver ( translateConfigContainer . config , this . httpClient ) ; return baseResolver . resolveByName ( modelName , languageCode ) ; } addConfig ( name ) { let containerConfig = translateContainer . getByName ( name ) ; if ( ! containerConfig ) translateContainer . set ( null , { translationName : name } ) ; } }