mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-19 11:02:58 +00:00
* 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
33 lines
655 B
JavaScript
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;
|