162 Use hook to merge component path with translation key
This commit is contained in:
+5
-5
@@ -16,11 +16,11 @@ import { determinePredictionText, formatWithOrdinalSuffix } from './helpers/home
|
|||||||
|
|
||||||
import { Colors, Fonts, Sizes, Spacing } from '../styles'
|
import { Colors, Fonts, Sizes, Spacing } from '../styles'
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
import { useTranslation } from 'react-i18next'
|
import useComponentTranslation from '../hooks/useComponentTranslation'
|
||||||
|
|
||||||
const Home = ({ navigate, setDate }) => {
|
const Home = ({ navigate, setDate }) => {
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useComponentTranslation('components.Home');
|
||||||
|
|
||||||
function navigateToCycleDayView() {
|
function navigateToCycleDayView() {
|
||||||
setDate(todayDateString)
|
setDate(todayDateString)
|
||||||
@@ -46,14 +46,14 @@ const Home = ({ navigate, setDate }) => {
|
|||||||
{cycleDayNumber &&
|
{cycleDayNumber &&
|
||||||
<View style={styles.line}>
|
<View style={styles.line}>
|
||||||
<AppText style={styles.whiteSubtitle}>{cycleDayText}</AppText>
|
<AppText style={styles.whiteSubtitle}>{cycleDayText}</AppText>
|
||||||
<AppText style={styles.turquoiseText}>{t('components.Home.cycleDay')}</AppText>
|
<AppText style={styles.turquoiseText}>{t('cycleDay')}</AppText>
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
{phase &&
|
{phase &&
|
||||||
<View style={styles.line}>
|
<View style={styles.line}>
|
||||||
<AppText style={styles.whiteSubtitle}>{formatWithOrdinalSuffix(phase)}</AppText>
|
<AppText style={styles.whiteSubtitle}>{formatWithOrdinalSuffix(phase)}</AppText>
|
||||||
<AppText style={styles.turquoiseText}>
|
<AppText style={styles.turquoiseText}>
|
||||||
{t('components.Home.cyclePhase')}
|
{t('cyclePhase')}
|
||||||
</AppText>
|
</AppText>
|
||||||
<AppText style={styles.turquoiseText}>{status}</AppText>
|
<AppText style={styles.turquoiseText}>{status}</AppText>
|
||||||
<Asterisk />
|
<Asterisk />
|
||||||
@@ -63,7 +63,7 @@ const Home = ({ navigate, setDate }) => {
|
|||||||
<AppText style={styles.turquoiseText}>{prediction}</AppText>
|
<AppText style={styles.turquoiseText}>{prediction}</AppText>
|
||||||
</View>
|
</View>
|
||||||
<Button isCTA isSmall={false} onPress={navigateToCycleDayView}>
|
<Button isCTA isSmall={false} onPress={navigateToCycleDayView}>
|
||||||
{t('components.Home.addDataForToday')}
|
{t('addDataForToday')}
|
||||||
</Button>
|
</Button>
|
||||||
{phase && (
|
{phase && (
|
||||||
<View style={styles.asteriskLine}>
|
<View style={styles.asteriskLine}>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
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 };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user