File tree Expand file tree Collapse file tree 3 files changed +33
-7
lines changed
client/packages/lowcoder-design Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 1- import { Translator } from "lowcoder-core" ;
1+ import { getI18nObjects , Translator } from "lowcoder-core" ;
22import * as localeData from "./locales" ;
3+ import { ReactNode } from "react" ;
34
4- export const { trans } = new Translator < typeof localeData . en > ( localeData , REACT_APP_LANGUAGES ) ;
5+ type transType = ( key : any , variables ?: any ) => string ;
6+ type transToNodeType = ( key : any , variables ?: any ) => ReactNode ;
7+
8+ let trans : transType ;
9+ let transToNode : transToNodeType ;
10+ let language = 'en' ;
11+
12+ export const initTranslator = async ( lang ?: string ) => {
13+ let langJson = await ( localeData as any ) [ lang || 'en' ] ( ) ;
14+ langJson = { [ lang || 'en' ] : langJson }
15+ const translator = new Translator < typeof langJson > (
16+ langJson ,
17+ REACT_APP_LANGUAGES ,
18+ [ lang || 'en' ]
19+ ) ;
20+
21+ language = translator . language ;
22+ transToNode = ( key : any , variables ?: any ) => translator . transToNode ?.( key , variables ) ;
23+ trans = ( key : any , variables ?: any ) => translator . trans ?.( key , variables ) ;
24+ }
25+
26+ const langJson = await ( localeData as any ) [ REACT_APP_LANGUAGES || 'en' ] ( ) ;
27+
28+ await initTranslator ( ) ;
29+
30+ export { language , trans , transToNode } ;
Original file line number Diff line number Diff line change 11// file examples: en, enGB, zh, zhHK
22// fallback example: current locale is zh-HK, fallback order is zhHK => zh => en
3- export * from "./en" ;
4- export * from "./zh" ;
5- export * from "./de" ;
6- export * from "./pt"
3+ export const en = async ( ) : Promise < Object > => await import ( "./en" ) . then ( module => module . en ) ;
4+ export const zh = async ( ) : Promise < Object > => await import ( "./zh" ) . then ( module => module . zh ) ;
5+ export const de = async ( ) : Promise < Object > => await import ( "./de" ) . then ( module => module . de ) ;
6+ export const pt = async ( ) : Promise < Object > => await import ( "./pt" ) . then ( module => module . pt ) ;
Original file line number Diff line number Diff line change 11{
22 "compilerOptions" : {
3- "target" : " es5 " ,
3+ "target" : " es2017 " ,
44 "experimentalDecorators" : true ,
55 "lib" : [" dom" , " dom.iterable" , " esnext" ],
66 "allowJs" : true ,
You can’t perform that action at this time.
0 commit comments