react-translate-maker
Version:
React translation module. Internationalize your great project.
22 lines • 723 B
JavaScript
import { useContext, useCallback } from 'react';
import TranslateContext from './TranslateContext';
import NamespaceContext from './NamespaceContext';
export default function ProvideTranslate(props) {
const {
children,
ignoreNamespace
} = props;
const namespace = useContext(NamespaceContext);
const {
translate
} = useContext(TranslateContext);
const t = useCallback((path, ...args) => {
const finallPath = namespace && !ignoreNamespace ? `${namespace}.${path}` : path;
return translate.get(finallPath, ...args);
}, [translate, namespace, ignoreNamespace]);
return children(t);
}
ProvideTranslate.defaultProps = {
ignoreNamespace: false
};
//# sourceMappingURL=ProvideTranslate.js.map