Skip to content

Commit

Permalink
i18n translate footer
Browse files Browse the repository at this point in the history
  • Loading branch information
bodobraegger committed Sep 1, 2023
1 parent 78bad90 commit f7f606f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
31 changes: 7 additions & 24 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { SectionT } from './Section';
import { Button, ButtonGroup, Truncate } from '@primer/react';
import { ArrowLeftIcon, ArrowRightIcon, ArrowUpIcon } from '@primer/octicons-react'
import ScrollButton from './ScrollButton';
import { withTranslation } from 'react-i18next';

type Props = {
t?: any;
Expand Down Expand Up @@ -37,24 +38,6 @@ function Footer({ t }: Props) {
nextSection = sections[0];
prevSection = sections[sections.length-1];
}

// localize the navigation buttons
let prevButtonText = "Previous Chapter";
let nextButtonText = "Next Chapter";
let homeButtonText = "Return to Start";
if (locale === 'de') {
prevButtonText = "Vorheriges Kapitel";
nextButtonText = "Nächstes Kapitel";
homeButtonText = "Zurück zum Start";
} else if (locale === 'fr') {
prevButtonText = "Chapitre Précédent";
nextButtonText = "Chapitre Suivant";
homeButtonText = "Retour au Début";
} else if (locale === 'it') {
prevButtonText = "Capitolo Precedente";
nextButtonText = "Prossimo Capitolo";
homeButtonText = "Ritorno all' Inizio";
}

var prevSlug = prevSection && prevSection.slug;
var nextSlug = nextSection && nextSection.slug;
Expand All @@ -73,25 +56,25 @@ function Footer({ t }: Props) {
leadingIcon={prevSection? ArrowLeftIcon: ArrowUpIcon}
>
{prevSection &&
<>{prevButtonText}<br/>
<>{t('footer.prevButtonText')}<br/>
<Truncate title={prevSection?.title} maxWidth={100}><i>{prevSection?.title}</i></Truncate>
</>
}
{!prevSection &&
<>{homeButtonText}<br/>&nbsp;</>
<>{t('footer.homeButtonText')}<br/>&nbsp;</>
}
</Button>
<Button size="large" className='btn-nav btn-footer pb-5 pt-5'
onClick={() => navigate(`/${nextSlug}`)}
trailingIcon={nextSection? ArrowRightIcon: ArrowUpIcon}
>
{nextSection &&
<>{nextButtonText}<br/>
<>{t('footer.nextButtonText')}<br/>
<Truncate title={nextSection?.title} maxWidth={100}><i>{nextSection?.title}</i></Truncate>
</>
}
{!nextSection &&
<>{homeButtonText}<br/>&nbsp;</>
<>{t('footer.homeButtonText')}<br/>&nbsp;</>
}
</Button>
</ButtonGroup>
Expand All @@ -102,7 +85,7 @@ function Footer({ t }: Props) {
onClick={() => navigate(`/${prevSlug}`)}
leadingIcon={ArrowUpIcon}
>
{homeButtonText}
{t('footer.homeButtonText')}
</Button>
</>
}
Expand All @@ -113,4 +96,4 @@ function Footer({ t }: Props) {

}

export default Footer
export default withTranslation()(Footer)
5 changes: 5 additions & 0 deletions src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
},
"scrollButton": {
"tooltip": "Nach Oben Scrollen"
},
"footer": {
"prevButtonText": "Vorheriges Kapitel",
"nextButtonText": "Nächstes Kapitel",
"homeButtonText": "Zurück zum Start"
}
}
}
5 changes: 5 additions & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
},
"scrollButton": {
"tooltip": "Scroll to Top"
},
"footer": {
"prevButtonText": "Previous Chapter",
"nextButtonText": "Next Chapter",
"homeButtonText": "Return to Start"
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
},
"scrollButton": {
"tooltip": "Remonter en Haut"
},
"footer": {
"prevButtonText": "Chapitre Précédent",
"nextButtonText": "Chapitre Suivant",
"homeButtonText": "Retour au Début"
}
}
}
5 changes: 5 additions & 0 deletions src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
},
"scrollButton": {
"tooltip": "Scorrere Verso l'Alto"
},
"footer": {
"prevButtonText": "Capitolo Precedente",
"nextButtonText": "Prossimo Capitolo",
"homeButtonText": "Ritorno all' Inizio"
}
}
}

0 comments on commit f7f606f

Please sign in to comment.