File tree Expand file tree Collapse file tree 8 files changed +34
-82
lines changed
docs/documentation/server_development/topics Expand file tree Collapse file tree 8 files changed +34
-82
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ import { KeycloakProvider } from "@keycloak/keycloak-ui-shared";
4242
4343The pages are translated using the `i18next` library.
4444You can set it up as described on their [website](https://react.i18next.com/).
45- If you want to use the translations that are provided then you need to add i18next-http -backend to your project and add:
45+ If you want to use the translations that are provided then you need to add ` i18next-fetch -backend` to your project and add:
4646
4747[source,javascript]
4848----
@@ -51,9 +51,9 @@ backend: {
5151 parse: (data: string) => {
5252 const messages = JSON.parse(data);
5353
54- const result: Record<string, string> = {};
55- messages.forEach((v ) => (result[v. key] = v. value)); //need to convert to record
56- return result ;
54+ return Object.fromEntries(
55+ messages.map(({ key, value } ) => [ key, value])
56+ ) ;
5757 },
5858},
5959----
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ import { KeycloakProvider } from "@keycloak/keycloak-ui-shared";
3333### Translation
3434
3535For the translation we use ` react-i18next ` you can [ set it up] ( https://react.i18next.com/ ) as described on their website.
36- If you want to use the translations that are provided then you need to add ` i18next-http -backend ` to your project and add:
36+ If you want to use the translations that are provided then you need to add ` i18next-fetch -backend ` to your project and add:
3737
3838``` ts
3939
@@ -42,9 +42,9 @@ backend: {
4242 parse : (data : string ) => {
4343 const messages = JSON .parse (data );
4444
45- const result : Record < string , string > = {};
46- messages .forEach (( v ) => ( result [ v . key ] = v . value ));
47- return result ;
45+ return Object . fromEntries (
46+ messages .map (({ key , value } ) => [ key , value ])
47+ ) ;
4848 },
4949},
5050```
Original file line number Diff line number Diff line change 3131 "@patternfly/react-icons" : " ^5.4.2" ,
3232 "@patternfly/react-table" : " ^5.4.16" ,
3333 "i18next" : " ^24.2.2" ,
34- "i18next-http -backend" : " ^3 .0.2 " ,
34+ "i18next-fetch -backend" : " ^6 .0.0 " ,
3535 "keycloak-js" : " ^26.2.0" ,
3636 "lodash-es" : " ^4.17.21" ,
3737 "react" : " ^18.3.1" ,
Original file line number Diff line number Diff line change 11import { LanguageDetectorModule , createInstance } from "i18next" ;
2- import HttpBackend from "i18next-http -backend" ;
2+ import FetchBackend from "i18next-fetch -backend" ;
33import { initReactI18next } from "react-i18next" ;
44
55import { environment } from "./environment" ;
@@ -32,16 +32,14 @@ export const i18n = createInstance({
3232 environment . serverBaseUrl ,
3333 `resources/${ environment . realm } /account/{{lng}}` ,
3434 ) ,
35- parse : ( data : string ) => {
36- const messages = JSON . parse ( data ) ;
35+ parse ( data : string ) {
36+ const messages : KeyValue [ ] = JSON . parse ( data ) ;
3737
38- const result : Record < string , string > = { } ;
39- messages . forEach ( ( v : KeyValue ) => ( result [ v . key ] = v . value ) ) ;
40- return result ;
38+ return Object . fromEntries ( messages . map ( ( { key, value } ) => [ key , value ] ) ) ;
4139 } ,
4240 } ,
4341} ) ;
4442
45- i18n . use ( HttpBackend ) ;
43+ i18n . use ( FetchBackend ) ;
4644i18n . use ( keycloakLanguageDetector ) ;
4745i18n . use ( initReactI18next ) ;
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ import { KeycloakProvider } from "@keycloak/keycloak-ui-shared";
3333### Translation
3434
3535For the translation we use ` react-i18next ` you can [ set it up] ( https://react.i18next.com/ ) as described on their website.
36- If you want to use the translations that are provided then you need to add ` i18next-http -backend ` to your project and add:
36+ If you want to use the translations that are provided then you need to add ` i18next-fetch -backend ` to your project and add:
3737
3838``` ts
3939
@@ -42,9 +42,9 @@ backend: {
4242 parse : (data : string ) => {
4343 const messages = JSON .parse (data );
4444
45- const result : Record < string , string > = {};
46- messages .forEach (( v ) => ( result [ v . key ] = v . value ));
47- return result ;
45+ return Object . fromEntries (
46+ messages .map (({ key , value } ) => [ key , value ])
47+ ) ;
4848 },
4949},
5050```
Original file line number Diff line number Diff line change 101101 "file-saver" : " ^2.0.5" ,
102102 "flat" : " ^6.0.1" ,
103103 "i18next" : " ^24.2.2" ,
104- "i18next-http -backend" : " ^3 .0.2 " ,
104+ "i18next-fetch -backend" : " ^6 .0.0 " ,
105105 "jszip" : " ^3.10.1" ,
106106 "keycloak-js" : " ^26.2.0" ,
107107 "lodash-es" : " ^4.17.21" ,
Original file line number Diff line number Diff line change 11import { createInstance } from "i18next" ;
2- import HttpBackend from "i18next-http -backend" ;
2+ import FetchBackend from "i18next-fetch -backend" ;
33import { initReactI18next } from "react-i18next" ;
44
55import { environment } from "../environment" ;
@@ -24,14 +24,12 @@ export const i18n = createInstance({
2424 `resources/{{ns}}/admin/{{lng}}` ,
2525 ) ,
2626 parse : ( data : string ) => {
27- const messages = JSON . parse ( data ) ;
27+ const messages : KeyValue [ ] = JSON . parse ( data ) ;
2828
29- const result : Record < string , string > = { } ;
30- messages . forEach ( ( v : KeyValue ) => ( result [ v . key ] = v . value ) ) ;
31- return result ;
29+ return Object . fromEntries ( messages . map ( ( { key, value } ) => [ key , value ] ) ) ;
3230 } ,
3331 } ,
3432} ) ;
3533
36- i18n . use ( HttpBackend ) ;
34+ i18n . use ( FetchBackend ) ;
3735i18n . use ( initReactI18next ) ;
You can’t perform that action at this time.
0 commit comments