import { RxTranslateConfig } from "../interface/rx-translate-config" ; import { TranslationModelData } from "../interface/translation-model-data" ; export const MultiLingualData = new ( class { private translationModelData : Array < TranslationModelData > = new Array < TranslationModelData > ( ) ; data : { [ key ] : any ; } = { } ; private keys : { [ key ] : boolean ; } = { } ; private contentKeysByLanguage : { [ key ] : string ; } = { } ; addOrUpdate ( key , data , translationName , languageCode ? ) { this . data [ key ] = data ; this . keys [ translationName ] = true ; if ( languageCode ) this . contentKeysByLanguage [ key ] = languageCode ; } addOrUpdateComponent ( key , data , instance , refMarkedId ) { let indexOf = this . translationModelData . findIndex ( t => t . instance == instance && t . key == key && t . rxRefMarkedId == refMarkedId ) ; if ( indexOf != - 1 ) this . translationModelData [ indexOf ] = { key : key , data : data , instance : instance , rxRefMarkedId : refMarkedId } ; else this . translationModelData . push ( { key : key , data : data , instance : instance , rxRefMarkedId : refMarkedId } ) ; } getComponentPropValue ( key , instance , refMarkedId ) { let indexOf = this . translationModelData . findIndex ( t => t . instance == instance && t . key == key && t . rxRefMarkedId == refMarkedId ) ; return indexOf != - 1 ? this . translationModelData [ indexOf ] . data : undefined ; } removeComponentPropValue ( instance , refMarkedId , keyName ? ) { let indexOf = - 1 ; if ( keyName ) indexOf = this . translationModelData . findIndex ( t => t . instance == instance && t . rxRefMarkedId == refMarkedId && t . key == keyName ) ; else { let result = this . translationModelData . filter ( t => t . instance == instance && t . rxRefMarkedId == refMarkedId ) ; for ( let data of result ) { this . translationModelData . splice ( this . translationModelData . indexOf ( data ) , 1 ) ; } } return indexOf != - 1 ? this . translationModelData . splice ( indexOf , 1 ) : undefined ; } contains ( key , languageCode ) { return this . data [ key ] ? this . contentKeysByLanguage [ key ] == languageCode : false ; } get ( key ) { return this . data [ key ] ? this . data [ key ] : undefined ; } clearInActives ( config ) { if ( ! config . cacheActiveLanguageObject || ( ! config . cacheActiveLanguageObject && ! config . cacheLanguageWiseObject ) ) Object . keys ( this . keys ) . forEach ( t => { if ( ! this . keys [ t ] && this . data [ t ] ) { delete this . data [ t ] ; } } ) ; } getActiveKeys ( ) { return Object . keys ( this . keys ) ; } remove ( key ) { this . keys [ key ] = undefined ; } } ) ;