theme.keycloak.v2.account.resources.widgets.Msg.js.map Maven / Gradle / Ivy
{"version":3,"file":"Msg.js","names":["React","Msg","Component","constructor","props","render","children","localizeWithChildren","msgKey","createElement","Fragment","localize","params","message","l18nMsg","processKey","parts","split","count","Children","map","child","i","undefined","length","forEach","value","index","processParam","replace","startsWith","endsWith","substring","param","key"],"sources":["../../src/app/widgets/Msg.tsx"],"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 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"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK;AASjB,OAAO,MAAMC,GAAG,SAASD,KAAK,CAACE,SAAS,CAAW;EAExCC,WAAWA,CAACC,KAAe,EAAE;IAChC,KAAK,CAACA,KAAK,CAAC;EAChB;EAEOC,MAAMA,CAAA,EAAoB;IAC7B,IAAI,IAAI,CAACD,KAAK,CAACE,QAAQ,EAAE;MACrB,OAAOL,GAAG,CAACM,oBAAoB,CAAC,IAAI,CAACH,KAAK,CAACI,MAAM,EAAE,IAAI,CAACJ,KAAK,CAACE,QAAQ,CAAC;IAC3E;IACA,oBACIN,KAAA,CAAAS,aAAA,CAACT,KAAK,CAACU,QAAQ,QAAET,GAAG,CAACU,QAAQ,CAAC,IAAI,CAACP,KAAK,CAACI,MAAM,EAAE,IAAI,CAACJ,KAAK,CAACQ,MAAM,CAAkB,CAAC;EAE7F;EAEA,OAAeL,oBAAoBA,CAACC,MAAc,EAAEF,QAAyB,EAAmB;IAC5F,MAAMO,OAAe,GAAGC,OAAO,CAAC,IAAI,CAACC,UAAU,CAACP,MAAM,CAAC,CAAC;IACxD,MAAMQ,KAAK,GAAGH,OAAO,CAACI,KAAK,CAAC,iBAAiB,CAAC;IAC9C,MAAMC,KAAK,GAAGlB,KAAK,CAACmB,QAAQ,CAACD,KAAK,CAACZ,QAAQ,CAAC;IAC5C,OAAON,KAAK,CAACmB,QAAQ,CAACC,GAAG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