1- import i18n from "i18next" ;
1+ import i18n , { FormatterModule } from "i18next" ;
22import { initReactI18next } from "react-i18next" ;
33
44import HttpBackend , { HttpBackendOptions } from "i18next-http-backend" ;
@@ -23,7 +23,7 @@ import trTRTrans from "./org/opencastproject/adminui/languages/lang-tr_TR.json";
2323import zhCNTrans from "./org/opencastproject/adminui/languages/lang-zh_CN.json" ;
2424import zhTWTrans from "./org/opencastproject/adminui/languages/lang-zh_TW.json" ;
2525import { 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
5168i18n
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