File tree 3 files changed +26
-2
lines changed
3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 8
8
"ios" : " expo run:ios" ,
9
9
"web" : " expo start --web" ,
10
10
"lint" : " tsc --noEmit && eslint ." ,
11
- "format" : " prettier --write ."
11
+ "format" : " prettier --write ." ,
12
+ "translations" : " ts-node ./scripts/load-translations.ts"
12
13
},
13
14
"dependencies" : {
14
15
"@eva-design/eva" : " ^2.2.0" ,
Original file line number Diff line number Diff line change
1
+ import fs from 'fs' ;
2
+ import path from 'path' ;
3
+
4
+ const i18nFolder = "./i18n" ;
5
+ const files = fs . readdirSync ( i18nFolder ) ;
6
+ const jsonFiles = files . filter ( file => file . endsWith ( '.json' ) ) . map ( file => path . basename ( file , '.json' ) ) ;
7
+
8
+
9
+ const imports = `import { Resource } from "i18next";\n\n` + jsonFiles . map ( lang => `import ${ lang } from "./${ lang } .json";` ) . join ( '\n' ) ;
10
+
11
+ const translationsObject = `const translations: Resource = {
12
+ ${ jsonFiles . map ( lang => `${ lang } : { translation: ${ lang } }` ) . join ( ',\n ' ) }
13
+ };
14
+
15
+ export default translations;
16
+ ` ;
17
+
18
+
19
+ const outputPath = "./i18n/index.ts" ;
20
+ const content = `${ imports } \n\n${ translationsObject } ` ;
21
+
22
+ fs . writeFileSync ( outputPath , content , 'utf-8' ) ;
23
+ console . log ( 'Finished loading translations.' ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"compilerOptions" : {},
3
- "extends" : "expo/tsconfig.base"
3
+ "extends" : " ./node_modules/ expo/tsconfig.base"
4
4
}
You can’t perform that action at this time.
0 commit comments