Skip to content
Snippets Groups Projects
Commit 0b447178 authored by Lisa Hillebrand's avatar Lisa Hillebrand
Browse files

162 Use hook to merge component path with translation key

parent f3cabe5c
No related branches found
No related tags found
No related merge requests found
......@@ -16,11 +16,11 @@ import { determinePredictionText, formatWithOrdinalSuffix } from './helpers/home
import { Colors, Fonts, Sizes, Spacing } from '../styles'
import { LocalDate } from 'js-joda'
import { useTranslation } from 'react-i18next'
import useComponentTranslation from '../hooks/useComponentTranslation'
const Home = ({ navigate, setDate }) => {
const { t } = useTranslation();
const { t } = useComponentTranslation('components.Home');
function navigateToCycleDayView() {
setDate(todayDateString)
......@@ -46,14 +46,14 @@ const Home = ({ navigate, setDate }) => {
{cycleDayNumber &&
<View style={styles.line}>
<AppText style={styles.whiteSubtitle}>{cycleDayText}</AppText>
<AppText style={styles.turquoiseText}>{t('components.Home.cycleDay')}</AppText>
<AppText style={styles.turquoiseText}>{t('cycleDay')}</AppText>
</View>
}
{phase &&
<View style={styles.line}>
<AppText style={styles.whiteSubtitle}>{formatWithOrdinalSuffix(phase)}</AppText>
<AppText style={styles.turquoiseText}>
{t('components.Home.cyclePhase')}
{t('cyclePhase')}
</AppText>
<AppText style={styles.turquoiseText}>{status}</AppText>
<Asterisk />
......@@ -63,7 +63,7 @@ const Home = ({ navigate, setDate }) => {
<AppText style={styles.turquoiseText}>{prediction}</AppText>
</View>
<Button isCTA isSmall={false} onPress={navigateToCycleDayView}>
{t('components.Home.addDataForToday')}
{t('addDataForToday')}
</Button>
{phase && (
<View style={styles.asteriskLine}>
......
import { useTranslation } from "react-i18next"
export default function useComponentTranslation(componentPath) {
const { t, i18n } = useTranslation();
function translate(code, options) {
const mergedPath = `${componentPath}.${code}`;
const translation = t(mergedPath, options);
return translation !== mergedPath ? translation : t(code, options);
}
return { t: translate, i18n };
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment