Skip to content

Commit 6f61ef2

Browse files
Swiftworkkibertoadmovermeyer
authored
fix: react-i18next, added better support for namespace overrides, corrected e2e-tests (#871)
Co-authored-by: Igor Savin <[email protected]> Co-authored-by: Michael Overmeyer <[email protected]>
1 parent 1f17ae9 commit 6f61ef2

File tree

13 files changed

+244
-38959
lines changed

13 files changed

+244
-38959
lines changed

examples/by-frameworks/react-i18next/.vscode/settings.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"i18n-ally.localesPaths": "public/locales",
33
"i18n-ally.enabledFrameworks": [
4-
"react",
5-
"i18next",
4+
"react-i18next",
65
"general"
76
],
87
"i18n-ally.namespace": true,

examples/by-frameworks/react-i18next/src/App.jsx

+26-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ import './App.css'
1010
class LegacyWelcomeClass extends Component {
1111
render() {
1212
const { t } = this.props
13-
const intl = useIntl()
1413
return (
1514
<div>
1615
<h2>Plain Text</h2>
1716
<h2>{t('translation.title')}</h2>
18-
<h2>{intl.formatPlural({ id: 'translation.title' })}</h2>
19-
<h2>{intl.formatMessage({ id: 'translation.title' })}</h2>
2017
</div>
2118
)
2219
}
@@ -52,7 +49,7 @@ function Page() {
5249
</div>
5350
<div>{t('translation.description.part2')}</div>
5451
{/* plain <Trans>, #423 */}
55-
<Trans>translation.description.part2</Trans>
52+
<Trans i18nKey="translation.description.part2">Fallback text</Trans>
5653
</div>
5754
)
5855
}
@@ -78,3 +75,28 @@ function Page3() {
7875
// explicit namespace
7976
t('translation:title')
8077
}
78+
79+
// hook with scope in options
80+
function Page4() {
81+
const { t } = useTranslation('pages/home')
82+
83+
t('title')
84+
85+
// explicit namespace
86+
t('title', { ns: 'translation' })
87+
}
88+
89+
90+
// component with scope in props
91+
function Page5() {
92+
const { t } = useTranslation('pages/home');
93+
94+
return (
95+
<div className="App">
96+
<Trans t={t} i18nKey="title"></Trans>
97+
{/* explicit namespace */}
98+
<Trans t={t} i18nKey="title" ns="translation"></Trans>
99+
</div>
100+
)
101+
}
102+

0 commit comments

Comments
 (0)