From a94dda65a823a1f191ffbc3981448adfae270fcc Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sat, 14 Jan 2023 00:54:37 +0100 Subject: [PATCH] translate tech title --- resources/js/components/pages/Technique.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/js/components/pages/Technique.js b/resources/js/components/pages/Technique.js index 19b56b7..8c202ed 100644 --- a/resources/js/components/pages/Technique.js +++ b/resources/js/components/pages/Technique.js @@ -1,5 +1,6 @@ import axios from 'axios'; import React, { useEffect, useState } from 'react'; +import { withTranslation } from 'react-i18next'; import { useParams } from 'react-router-dom'; import ErrorBoundary from '../common/ErrorBoundary'; @@ -7,6 +8,8 @@ import ErrorMessage from '../common/ErrorMessage'; import Loading from '../common/Loading'; import NotFound from '../pages/NotFound'; import Detail from '../techniques/Detail'; +import { getTranslation } from '../../helpers/Technique'; +import i18n from '../../i18n'; const Technique = () => { const params = useParams(); @@ -25,7 +28,6 @@ const Technique = () => { setError(null); setLoading(false); setTechnique(response.data); - window.document.title = response.data.title; }) .catch(error => { setError(error); @@ -37,6 +39,12 @@ const Technique = () => { }; }, [name]); + useEffect(() => { + if (technique) { + window.document.title = getTranslation(technique, 'title', i18n.language); + } + }, [technique, i18n.language]); + if (loading) { return ; } @@ -54,4 +62,4 @@ const Technique = () => { ; }; -export default Technique; +export default withTranslation()(Technique); -- 2.39.2