Created
May 21, 2019 15:50
-
-
Save coryf/41f964fc815107276cfd0f2343774685 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import i18n from 'i18n-js' | |
import { sanitize } from 'dompurify' | |
import _ from 'lodash' | |
export const htmlTranslate = (scope, options) => { | |
if (!scope.endsWith('_html')) { | |
return i18n.t(scope, options) | |
} | |
const tag = options['tag'] || 'span' | |
const escapedInterpolations = _.mapValues(options, dompurify) | |
const html = i18n.t(scope, escapedInterpolations) | |
return React.createElement(tag, { dangerouslySetInnerHTML: { __html: html } }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment