Language as window.language for access in pure function

This commit is contained in:
James Barnsley
2020-07-05 20:58:39 +12:00
parent 78ec0eff26
commit 1158fb7c2f
14 changed files with 17353 additions and 136 deletions

View File

@ -7,9 +7,11 @@ import { titleCase } from '../util/helpers';
const PARAMS_REG_EXP = '%{(.*?)}';
const paramsRegExp = new RegExp(PARAMS_REG_EXP, 'g');
const content = (path, params = {}, transform, dictionary) => {
const content = (path, params = {}, transform) => {
console.log(window.language);
const dictionary = dictionaries[window.language || 'en'] || dictionaries.en;
let value = get((dictionary || dictionaries.en), path, '');
let value = get((dictionary), path, '');
value = value.replace(
paramsRegExp,
(replaceText, key) => params.hasOwnProperty(key) ? params[key] : '',
@ -32,16 +34,12 @@ const content = (path, params = {}, transform, dictionary) => {
return value;
};
const Content = ({ path, params = {}, transform, children }) => {
const language = useSelector((state) => state.ui.language);
const dictionary = dictionaries[language];
return (
<Fragment>
{content(path, params, transform, dictionary)}
{children}
</Fragment>
);
}
const Content = ({ path, params = {}, transform, children }) => (
<Fragment>
{content(path, params, transform)}
{children}
</Fragment>
);
export default {
Content,