Skip to content

Commit b964bca

Browse files
authored
Update and consolidate i18n (#3313)
1 parent 34b59b5 commit b964bca

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
"distinct-colors": "^3.0.0",
5656
"history": "^5.3.0",
5757
"http-status-codes": "^2.3.0",
58-
"i18next": "^23.4.6",
58+
"i18next": "^23.14.0",
5959
"i18next-browser-languagedetector": "^8.0.0",
60-
"i18next-http-backend": "^2.2.2",
60+
"i18next-http-backend": "^2.6.0",
6161
"js-base64": "^3.7.7",
6262
"make-dir": "^4.0.0",
6363
"material-react-table": "^2.9.2",
@@ -70,7 +70,7 @@
7070
"react-beautiful-dnd": "^13.1.1",
7171
"react-chartjs-2": "^5.2.0",
7272
"react-dom": "^18.2.0",
73-
"react-i18next": "^14.1.2",
73+
"react-i18next": "^15.0.1",
7474
"react-modal": "^3.16.1",
7575
"react-redux": "^8.1.3",
7676
"react-router-dom": "^6.16.0",

src/i18n.ts renamed to src/i18n/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// https://dev.to/adrai/how-to-properly-internationalize-a-react-application-using-i18next-3hdb#getting-started
22
import i18n from "i18next";
33
import LanguageDetector from "i18next-browser-languagedetector";
4-
import Backend from "i18next-http-backend";
4+
import Backend, { type HttpBackendOptions } from "i18next-http-backend";
55
import { initReactI18next } from "react-i18next";
66

77
import { getCurrentUser } from "backend/localStorage";
@@ -18,17 +18,17 @@ i18n
1818
.use(Backend)
1919
.use(LanguageDetector)
2020
.use(initReactI18next)
21-
.init(
21+
.init<HttpBackendOptions>(
2222
{
2323
//debug: true, // Uncomment to troubleshoot
2424
returnNull: false,
25-
// detection: options,
2625
// ignoring localStorage and cookies for the detection order lets the user change languages
2726
// more easily (just switch in the browser and reload, instead of clearing all site data)
2827
detection: { order: ["queryString", "path", "navigator"] },
2928
supportedLngs: i18nLangs,
30-
// nonExplicitSupportedLngs will (e.g.) use 'es' if the browser is 'es-MX'
31-
nonExplicitSupportedLngs: true,
29+
// "languageOnly" means use only the language part (first subtag) of the full language tag;
30+
// e.g., if the user's browser is set to 'es-MX', we just use 'es'
31+
load: "languageOnly",
3232
fallbackLng: i18nFallbacks,
3333
interpolation: { escapeValue: false },
3434
},

src/tests/i18nMock.ts renamed to src/i18n/tests/i18nMock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Adapted from https://react.i18next.com/misc/testing
22
* (In most cases, this isn't needed.
3-
* Instead you can use tests/reactI18nextMock.ts to mock out i18n completely.)
3+
* Instead you can use i18n/tests/reactI18nextMock.ts to mock out i18n completely.)
44
* For a simple i18next wrapper, add the following to a test file:
55
* * import { I18nextProvider } from "react-i18next";
6-
* * import i18n from "tests/i18nMock";
6+
* * import i18n from "i18n/tests/i18nMock";
77
* Then wrap the component being rendered with <I18nextProvider i18n={i18n}> */
88

99
import i18n from "i18next";

src/tests/reactI18nextMock.ts renamed to src/i18n/tests/reactI18nextMock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* Use `import "tests/reactI18nextMock.ts";` in `setupTests.js` to mock i18next globally.
2-
* (For testing components with `Trans`, see tests/i18nMock.ts instead.)
1+
/* Use `import "i18n/tests/reactI18nextMock.ts";` in `setupTests.js` to mock i18next globally.
2+
* (For testing components with `Trans`, see i18n/tests/i18nMock.ts instead.)
33
* This import should occur before other internal imports that use `react-i18next`. */
44

55
jest.mock("react-i18next", () => ({

src/setupTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "tests/reactI18nextMock";
1+
import "i18n/tests/reactI18nextMock";
22

33
// Force tests to fail on console.error and console.warn
44
global.console.error = (message) => {

0 commit comments

Comments
 (0)