You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 989B

1234567891011121314151617181920212223242526272829303132
  1. import { translate as reactTranslate } from 'react-i18next';
  2. import React from 'react';
  3. /**
  4. * Wrap a translatable component.
  5. *
  6. * @param {Component} component - The component to wrap.
  7. * @returns {Component} The wrapped component.
  8. */
  9. export function translate(component) {
  10. // use the default list of namespaces
  11. return reactTranslate([ 'main', 'languages' ], { wait: true })(component);
  12. }
  13. /**
  14. * Translates key and prepares data to be passed to dangerouslySetInnerHTML.
  15. * Used when translation text contains html.
  16. *
  17. * @param {func} t - Translate function.
  18. * @param {string} key - The key to translate.
  19. * @param {Array} options - Optional options.
  20. * @returns {XML} A span using dangerouslySetInnerHTML to insert html text.
  21. */
  22. export function translateToHTML(t, key, options = {}) {
  23. /* eslint-disable react/no-danger */
  24. return (
  25. <span
  26. dangerouslySetInnerHTML = {{ __html: t(key, options) }} />
  27. );
  28. /* eslint-enable react/no-danger */
  29. }