Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: react-i18next, added better support for namespace overrides, corrected e2e-tests #871

Merged
merged 8 commits into from
Apr 24, 2023
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