{"version":3,"sources":["../../src/app/widgets/Msg.tsx"],"names":["React","Msg","Component","constructor","props","render","children","localizeWithChildren","msgKey","localize","params","message","l18nMsg","processKey","parts","split","count","Children","map","child","i","undefined","length","forEach","value","index","processParam","replace","unescape","startsWith","endsWith","substring","param","key"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,KAAKA,KAAZ;AASA,OAAO,MAAMC,GAAN,SAAkBD,KAAK,CAACE,SAAxB,CAA4C;AAExCC,EAAAA,WAAW,CAACC,KAAD,EAAkB;AAChC,UAAMA,KAAN;AACH;;AAEMC,EAAAA,MAAM,GAAoB;AAC7B,QAAI,KAAKD,KAAL,CAAWE,QAAf,EAAyB;AACrB,aAAOL,GAAG,CAACM,oBAAJ,CAAyB,KAAKH,KAAL,CAAWI,MAApC,EAA4C,KAAKJ,KAAL,CAAWE,QAAvD,CAAP;AACH;;AACD,WACI,oBAAC,KAAD,CAAO,QAAP,QAAiBL,GAAG,CAACQ,QAAJ,CAAa,KAAKL,KAAL,CAAWI,MAAxB,EAAgC,KAAKJ,KAAL,CAAWM,MAA3C,CAAjB,CADJ;AAGH;;AAEkC,SAApBH,oBAAoB,CAACC,MAAD,EAAiBF,QAAjB,EAA6D;AAC5F,UAAMK,OAAe,GAAGC,OAAO,CAAC,KAAKC,UAAL,CAAgBL,MAAhB,CAAD,CAA/B;AACA,UAAMM,KAAK,GAAGH,OAAO,CAACI,KAAR,CAAc,iBAAd,CAAd;AACA,UAAMC,KAAK,GAAGhB,KAAK,CAACiB,QAAN,CAAeD,KAAf,CAAqBV,QAArB,CAAd;AACA,WAAON,KAAK,CAACiB,QAAN,CAAeC,GAAf,CAAmBZ,QAAnB,EAA6B,CAACa,KAAD,EAAQC,CAAR,KAChC,CAACN,KAAK,CAACM,CAAD,CAAN,EAAWD,KAAX,EAAkBH,KAAK,KAAKI,CAAC,GAAG,CAAd,GAAkBN,KAAK,CAACE,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AAEA,QAAIE,KAAa,GAAGZ,OAAO,CAACqB,GAAD,CAA3B;AACA,QAAIT,KAAK,KAAKH,SAAd,EAAyB,OAAOW,KAAP;AAEzB,WAAOR,KAAP;AACH;;AAzD8C","sourcesContent":["/*\n * Copyright 2018 Red Hat, Inc. and/or its affiliates.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as React from 'react';\n\ndeclare const l18nMsg: {[key: string]: string};\n\nexport interface MsgProps {\n readonly msgKey: string;\n readonly params?: string[];\n}\n\nexport class Msg extends React.Component {\n\n public constructor(props: MsgProps) {\n super(props);\n }\n\n public render(): React.ReactNode {\n if (this.props.children) {\n return Msg.localizeWithChildren(this.props.msgKey, this.props.children);\n }\n return (\n {Msg.localize(this.props.msgKey, this.props.params)}\n );\n }\n\n private static localizeWithChildren(msgKey: string, children: React.ReactNode): React.ReactNode {\n const message: string = l18nMsg[this.processKey(msgKey)];\n const parts = message.split(/\\{\\{param_\\d*}}/);\n const count = React.Children.count(children);\n return React.Children.map(children, (child, i) =>\n [parts[i], child, count === i + 1 ? parts[count] : '']\n );\n }\n\n public static localize(msgKey: string, params?: string[]): string {\n let message: string = l18nMsg[this.processKey(msgKey)];\n if (message === undefined) message = msgKey;\n\n if ((params !== undefined) && (params.length > 0)) {\n params.forEach((value: string, index: number) => {\n value = this.processParam(value);\n message = message.replace('{{param_'+ index + '}}', value);\n })\n }\n\n return unescape(message);\n }\n\n // if the message key has Freemarker syntax, remove it\n private static processKey(msgKey: string): string {\n if (!(msgKey.startsWith('${') && msgKey.endsWith('}'))) return msgKey;\n\n // remove Freemarker syntax\n return msgKey.substring(2, msgKey.length - 1);\n }\n\n // if the param has Freemarker syntax, try to look up its value\n private static processParam(param: string): string {\n if (!(param.startsWith('${') && param.endsWith('}'))) return param;\n\n // remove Freemarker syntax\n const key: string = param.substring(2, param.length - 1);\n\n let value: string = l18nMsg[key];\n if (value === undefined) return param;\n\n return value;\n }\n}\n"],"file":"Msg.js"}