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.0.4
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.0.5
Choose a head ref
  • 3 commits
  • 7 files changed
  • 2 contributors

Commits on Feb 6, 2024

  1. Fix/bug 1691 preserving change language binding (#1720)

    * test: bug 1691 second attempt, add test for actual use of i18n.changeLanguage with useTranslation
    
    * fix: (pre-cleanup) bug 1691 cherry pick of 168b8f0: use memoization of fixedT function,
    
    bad impl, breaks test that was introduced in parent commit, verifying bug here: #1716 (comment)
    
    * fix: (pre-cleanup) bug 1691 fixing dev issue: regenerate a new t fn everywhere
    
    other than where the bug was occurring, and keep shallow routing working via dependency list of useCallback hook.  Fixes test broken by parent commit.
    
    * style: cleanup debug messages for bug 1691
    
    * build: bug 1691 npm run build
    timheilman authored Feb 6, 2024
    Copy the full SHA
    dc36d69 View commit details
  2. release

    adrai committed Feb 6, 2024
    Copy the full SHA
    78a24ab View commit details
  3. 14.0.5

    adrai committed Feb 6, 2024
    Copy the full SHA
    851a17d View commit details
Showing with 71 additions and 20 deletions.
  1. +4 −0 CHANGELOG.md
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +13 −7 react-i18next.js
  5. +1 −1 react-i18next.min.js
  6. +34 −9 src/useTranslation.js
  7. +16 −0 test/useTranslation.spec.jsx
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 14.0.5

- Fix [1691](https://github.com/i18next/react-i18next/issues/1691) for strict mode, by preserving change language binding [1720](https://github.com/i18next/react-i18next/pull/1720)

### 14.0.4

- fix interpolation of the count prop [1719](https://github.com/i18next/react-i18next/issues/1719)
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.0.4",
"version": "14.0.5",
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
"main": "dist/commonjs/index.js",
"types": "./index.d.mts",
20 changes: 13 additions & 7 deletions react-i18next.js
Original file line number Diff line number Diff line change
@@ -612,6 +612,12 @@
}, [value, ignore]);
return ref.current;
};
function alwaysNewT(i18n, language, namespace, keyPrefix) {
return i18n.getFixedT(language, namespace, keyPrefix);
}
function useMemoizedT(i18n, language, namespace, keyPrefix) {
return react.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
}
function useTranslation(ns) {
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const {
@@ -650,9 +656,9 @@
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
function getT() {
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
}
const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
const getT = () => memoGetT;
const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
const [t, setT] = react.useState(getT);
let joinedNS = namespaces.join();
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
@@ -667,19 +673,19 @@
if (!ready && !useSuspense) {
if (props.lng) {
loadLanguages(i18n, props.lng, namespaces, () => {
if (isMounted.current) setT(getT);
if (isMounted.current) setT(getNewT);
});
} else {
loadNamespaces(i18n, namespaces, () => {
if (isMounted.current) setT(getT);
if (isMounted.current) setT(getNewT);
});
}
}
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
setT(getT);
setT(getNewT);
}
function boundReset() {
if (isMounted.current) setT(getT);
if (isMounted.current) setT(getNewT);
}
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
Loading