Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: i18next/react-i18next
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v14.1.0
Choose a base ref
...
head repository: i18next/react-i18next
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v14.1.1
Choose a head ref
  • 3 commits
  • 7 files changed
  • 2 contributors

Commits on Apr 2, 2024

  1. Update CHANGELOG.md (#1741)

    RealTayy authored Apr 2, 2024
    Copy the full SHA
    f8d0111 View commit details

Commits on Apr 23, 2024

  1. do not modify passed tOptions context property to address #1745

    adrai committed Apr 23, 2024
    Copy the full SHA
    b8a0d8c View commit details
  2. 14.1.1

    adrai committed Apr 23, 2024
    Copy the full SHA
    70176d9 View commit details
Showing with 38 additions and 8 deletions.
  1. +5 −1 CHANGELOG.md
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +1 −1 react-i18next.js
  5. +1 −1 react-i18next.min.js
  6. +1 −2 src/TransWithoutContext.js
  7. +27 −0 test/trans.render.spec.jsx
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
### 14.1.1

- do not modify passed tOptions context property to address [1745](https://github.com/i18next/react-i18next/issues/1745)

### 14.1.0

- types(`Trans`): add typechecking on context prop [1732](https://github.com/i18next/react-i18next/pull/1732) (might brake if using "internal" `Trans` or `TransProps`)
- types(`Trans`): add typechecking on context prop [1732](https://github.com/i18next/react-i18next/pull/1732) (might break if using "internal" `Trans` or `TransProps`)

### 14.0.8

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-i18next",
"version": "14.1.0",
"version": "14.1.1",
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
"main": "dist/commonjs/index.js",
"types": "./index.d.mts",
2 changes: 1 addition & 1 deletion react-i18next.js
Original file line number Diff line number Diff line change
@@ -459,7 +459,6 @@
return children;
}
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
tOptions.context = context;
const reactI18nextOptions = {
...getDefaults(),
...(i18n.options && i18n.options.react)
@@ -482,6 +481,7 @@
}
const combinedTOpts = {
...tOptions,
context: context || tOptions.context,
count,
...values,
defaultValue,
2 changes: 1 addition & 1 deletion react-i18next.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/TransWithoutContext.js
Original file line number Diff line number Diff line change
@@ -329,8 +329,6 @@ export function Trans({

const t = tFromProps || i18n.t.bind(i18n) || ((k) => k);

tOptions.context = context;

const reactI18nextOptions = { ...getDefaults(), ...(i18n.options && i18n.options.react) };

// prepare having a namespace
@@ -353,6 +351,7 @@ export function Trans({
}
const combinedTOpts = {
...tOptions,
context: context || tOptions.context, // Add `context` from the props or fallback to the value from `tOptions`
count,
...values,
defaultValue,
27 changes: 27 additions & 0 deletions test/trans.render.spec.jsx
Original file line number Diff line number Diff line change
@@ -810,6 +810,33 @@ describe('trans with custom unescape', () => {
});
});

describe('trans with context via tOptions', () => {
const tOptions = { context: 'home' };
function TestComponent({ parent }) {
return (
<Trans i18nKey="testTransWithCtx" tOptions={tOptions} parent={parent}>
Open <Link to="/msgs">here</Link>.
</Trans>
);
}

it('should render correct content', () => {
const { container } = render(<TestComponent />);
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
Go
<a
href="/msgs"
>
home
</a>
.
</div>
`);
expect(tOptions).to.have.property('context', 'home');
});
});

describe('trans with context property', () => {
function TestComponent({ parent }) {
return (