Skip to content

Commit 05cbf1f

Browse files
committed
Update i18n to major version 26
Major version 26 has a breaking change that affects us, this patch should deal with that.
1 parent b636241 commit 05cbf1f

3 files changed

Lines changed: 76 additions & 46 deletions

File tree

package-lock.json

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

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
"focus-trap-react": "^12.0.0",
2020
"formik": "^2.4.9",
2121
"http-proxy-middleware": "^3.0.5",
22-
"i18next": "25.8.11",
22+
"i18next": "26.0.7",
2323
"i18next-browser-languagedetector": "^8.2.1",
24-
"i18next-http-backend": "^3.0.5",
24+
"i18next-http-backend": "^3.0.6",
2525
"lodash": "^4.17.23",
2626
"react": "^19.2.4",
2727
"react-chartjs-2": "^5.3.1",
2828
"react-datepicker": "^8.8.0",
2929
"react-dom": "^19.2.4",
3030
"react-hotkeys-hook": "^5.2.4",
31-
"react-i18next": "16.5.0",
31+
"react-i18next": "17.0.4",
3232
"react-icons": "^5.5.0",
3333
"react-redux": "^9.2.0",
3434
"react-router": "^7.13.0",
@@ -67,14 +67,14 @@
6767
"@types/node": "^25.3.0",
6868
"@types/react-dom": "^19.2.3",
6969
"@types/uuid": "^11.0.0",
70+
"@vitejs/plugin-react": "^6.0.1",
7071
"eslint": "^9.39.2",
7172
"prop-types": "^15.8.1",
7273
"sass": "^1.97.3",
7374
"typescript": "^5.9.3",
7475
"typescript-eslint": "^8.56.0",
7576
"uuid": "^13.0.0",
7677
"vite": "^8.0.9",
77-
"@vitejs/plugin-react": "^6.0.1",
7878
"vitest": "^4.0.18"
7979
}
8080
}

src/i18n/i18n.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import i18n from "i18next";
1+
import i18n, { FormatterModule } from "i18next";
22
import { initReactI18next } from "react-i18next";
33

44
import HttpBackend, { HttpBackendOptions } from "i18next-http-backend";
@@ -23,7 +23,7 @@ import trTRTrans from "./org/opencastproject/adminui/languages/lang-tr_TR.json";
2323
import zhCNTrans from "./org/opencastproject/adminui/languages/lang-zh_CN.json";
2424
import zhTWTrans from "./org/opencastproject/adminui/languages/lang-zh_TW.json";
2525
import { getCurrentLanguageInformation } from "../utils/utils";
26-
import { format } from "date-fns/format";
26+
import { format as dateFnsFormat } from "date-fns/format";
2727

2828
// Assignment of language code to translation file
2929
// !!! If translation file of a new language is added, please add assignment here, too !!!
@@ -47,29 +47,39 @@ const resources = {
4747
"zh-TW": { translation: zhTWTrans },
4848
} as const;
4949

50+
const myFormatter: FormatterModule = {
51+
type: "formatter",
52+
init(_services, _i18nextOptions) {},
53+
format(value, format, lng, _options) {
54+
if (value instanceof Date && format && lng) {
55+
return dateFnsFormat(value, format, {
56+
locale: getCurrentLanguageInformation(lng)?.dateLocale,
57+
});
58+
}
59+
60+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
61+
return value;
62+
},
63+
add(_name, _fc) { },
64+
addCached(_name, _fc) { },
65+
};
66+
5067
// Configuration of i18next
5168
i18n
5269
.use(HttpBackend)
5370
.use(LanguageDetector)
5471
.use(initReactI18next)
72+
.use(myFormatter)
5573
.init<HttpBackendOptions>({
5674
resources,
5775
fallbackLng: "en-US",
5876
debug: false,
5977

6078
interpolation: {
6179
escapeValue: false,
62-
format: function (value, formatStr, lng) {
63-
if (value instanceof Date && formatStr && lng) {
64-
return format(value, formatStr, {
65-
locale: getCurrentLanguageInformation(lng)?.dateLocale,
66-
});
67-
}
68-
69-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
70-
return value;
71-
},
80+
alwaysFormat: true,
7281
},
82+
7383
react: {
7484
useSuspense: false,
7585
},

0 commit comments

Comments
 (0)