Jérémie Pardou d875eefed0
Migrate to functionnal components (#232)
* Refactor Home component

* Refactor Welcome

* Refactor small components

* Refactor Nav component

* refactor Settings

* Refactor Chat

* Refactor New message notifications

* Fix tests

* Remove tooltip

* Remove react-simple-dropdown

* Change to last redux

* Switch to redux hooks

* Add github action
2023-12-30 17:53:50 +01:00

33 lines
655 B
JavaScript

import PropTypes from 'prop-types';
import _ from 'lodash';
import { getTranslations } from '@/i18n';
const regex = /{(.*?)}/g;
const T = ({ language, path, data }) => {
const t = getTranslations(language);
const englishT = getTranslations('en');
const str = _.get(t, path, '') || _.get(englishT, path, '');
let string = str.split(regex);
// Data for string interpolation
if (data) {
string = string.map(word => {
if (data[word]) {
return data[word];
}
return word;
});
return <span>{string}</span>;
}
return string;
};
T.propTypes = {
path: PropTypes.string.isRequired,
};
export default T;