class I18nService { private static messages : any ; param messagesConfig public setMessages ( messagesConfig ) { I18nService . messages = messagesConfig ; } param key param country param locale public get ( key , country ? , locale ? ) { let message = this . getMessage ( key , country , locale ) ; return message ? message : key ; } private getMessage ( key , country ? , locale ? ) { country = country ? country : "en" ; locale = locale ? locale : "US" ; return I18nService . messages [ country + "-" + locale ] [ key ] ; } private static configure ( messagesConfig ) { I18nService . messages = messagesConfig ; } public onMessagesResponse ( response ) { return response . json ( ) . then ( I18nService . onMessagesParsed ) ; } private static onMessagesParsed ( result ) { I18nService . configure ( result [ "messages" ] ) ; } public format ( key , values , country ? , locale ? ) { return this . get ( key , country , locale ) . replace ( /{(\d+)}/g , ( match , num ) => { return typeof values [ num ] !== "undefined" ? values [ num ] : match ; } ) ; } } export const Messages = new I18nService ( ) ;