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 1.1KB

12345678910111213141516171819202122232425262728293031
  1. import React from 'react';
  2. import { translate as reactI18nextTranslate } from 'react-i18next';
  3. /**
  4. * Wraps a specific React Component in order to enable translations in it.
  5. *
  6. * @param {Component} component - The React Component to wrap.
  7. * @returns {Component} The React Component which wraps {@link component} and
  8. * enables translations in it.
  9. */
  10. export function translate(component) {
  11. // Use the default list of namespaces.
  12. return (
  13. reactI18nextTranslate([ 'main', 'languages' ], { wait: true })(
  14. component));
  15. }
  16. /**
  17. * Translates a specific key to text containing HTML via a specific translate
  18. * function.
  19. *
  20. * @param {Function} t - The translate function.
  21. * @param {string} key - The key to translate.
  22. * @param {Array<*>} options - The options, if any, to pass to {@link t}.
  23. * @returns {ReactElement} A ReactElement which depicts the translated HTML
  24. * text.
  25. */
  26. export function translateToHTML(t, key, options = {}) {
  27. // eslint-disable-next-line react/no-danger
  28. return <span dangerouslySetInnerHTML = {{ __html: t(key, options) }} />;
  29. }