Skip to content

Commit

Permalink
fix: react-i18next, added better support for namespace overrides, cor…
Browse files Browse the repository at this point in the history
…rected e2e-tests (lokalise#871)

Co-authored-by: Igor Savin <iselwin@gmail.com>
Co-authored-by: Michael Overmeyer <michael@overmeyer.io>
  • Loading branch information
3 people authored and huacnlee committed Aug 28, 2023
1 parent 699af33 commit 6c6f336
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 38,959 deletions.
3 changes: 1 addition & 2 deletions examples/by-frameworks/react-i18next/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"i18n-ally.localesPaths": "public/locales",
"i18n-ally.enabledFrameworks": [
"react",
"i18next",
"react-i18next",
"general"
],
"i18n-ally.namespace": true,
Expand Down
30 changes: 26 additions & 4 deletions examples/by-frameworks/react-i18next/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import './App.css'
class LegacyWelcomeClass extends Component {
render() {
const { t } = this.props
const intl = useIntl()
return (
<div>
<h2>Plain Text</h2>
<h2>{t('translation.title')}</h2>
<h2>{intl.formatPlural({ id: 'translation.title' })}</h2>
<h2>{intl.formatMessage({ id: 'translation.title' })}</h2>
</div>
)
}
Expand Down Expand Up @@ -52,7 +49,7 @@ function Page() {
</div>
<div>{t('translation.description.part2')}</div>
{/* plain <Trans>, #423 */}
<Trans>translation.description.part2</Trans>
<Trans i18nKey="translation.description.part2">Fallback text</Trans>
</div>
)
}
Expand All @@ -78,3 +75,28 @@ function Page3() {
// explicit namespace
t('translation:title')
}

// hook with scope in options
function Page4() {
const { t } = useTranslation('pages/home')

t('title')

// explicit namespace
t('title', { ns: 'translation' })
}


// component with scope in props
function Page5() {
const { t } = useTranslation('pages/home');

return (
<div className="App">
<Trans t={t} i18nKey="title"></Trans>
{/* explicit namespace */}
<Trans t={t} i18nKey="title" ns="translation"></Trans>
</div>
)
}

Loading

0 comments on commit 6c6f336

Please sign in to comment.