File tree Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -38,12 +38,28 @@ export const parseAll = (folderPath: string): { name: string; path: string }[] =
38
38
const lang = { }
39
39
40
40
fs . readdirSync ( folderPath + path . sep + folder )
41
- . filter ( ( file ) => ! fs . statSync ( folderPath + path . sep + folder + path . sep + file ) . isDirectory ( ) )
42
41
. sort ( )
43
- . forEach ( ( file ) => {
44
- lang [ file . replace ( / \. \w + $ / , '' ) ] = parse (
45
- fs . readFileSync ( folderPath + path . sep + folder + path . sep + file ) . toString ( )
46
- )
42
+ . forEach ( ( langFolderItem ) => {
43
+ const langFolderPath = folderPath + path . sep + folder
44
+ const langFolderItemPath = langFolderPath + path . sep + langFolderItem
45
+
46
+ if ( fs . statSync ( langFolderItemPath ) . isDirectory ( ) ) {
47
+ // Lang sub folder
48
+ const subFolderFileKey = langFolderItem . replace ( / \. \w + $ / , '' )
49
+ lang [ subFolderFileKey ] = { }
50
+
51
+ fs . readdirSync ( langFolderItemPath )
52
+ . filter ( ( file ) => ! fs . statSync ( langFolderItemPath + path . sep + file ) . isDirectory ( ) )
53
+ . sort ( )
54
+ . forEach ( ( file ) => {
55
+ lang [ subFolderFileKey ] [ file . replace ( / \. \w + $ / , '' ) ] = parse (
56
+ fs . readFileSync ( langFolderItemPath + path . sep + file ) . toString ( )
57
+ )
58
+ } )
59
+ } else {
60
+ // Lang file
61
+ lang [ langFolderItem . replace ( / \. \w + $ / , '' ) ] = parse ( fs . readFileSync ( langFolderItemPath ) . toString ( ) )
62
+ }
47
63
} )
48
64
49
65
data . push ( {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ return [
4
+ 'car ' => 'Car|Cars ' ,
5
+ 'is_electric ' => 'Electric ' ,
6
+ 'charge_speed ' => 'Charge speed ' ,
7
+ 'foo ' => [
8
+ 'level1 ' => [
9
+ 'level2 ' => 'barpt '
10
+ ]
11
+ ],
12
+ ];
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ return [
4
+ 'user ' => 'User|Users ' ,
5
+ 'first_name ' => 'First name ' ,
6
+ 'sub_dir_support_is_amazing ' => 'Subdirectory support is amazing ' ,
7
+ ];
Original file line number Diff line number Diff line change @@ -21,6 +21,15 @@ it('creates a file for each lang', () => {
21
21
expect ( langPt [ 'auth.foo.level1.level2' ] ) . toBe ( 'barpt' ) ;
22
22
} ) ;
23
23
24
+ it ( 'includes .php lang file in subdirectory in .json' , ( ) => {
25
+ const files = parseAll ( __dirname + '/fixtures/lang/' ) ;
26
+ const langEn = JSON . parse ( fs . readFileSync ( files [ 0 ] . path ) . toString ( ) ) ;
27
+
28
+ expect ( langEn [ 'domain.user.sub_dir_support_is_amazing' ] ) . toBe ( 'Subdirectory support is amazing' ) ;
29
+ expect ( langEn [ 'domain.car.is_electric' ] ) . toBe ( 'Electric' ) ;
30
+ expect ( langEn [ 'domain.car.foo.level1.level2' ] ) . toBe ( 'barpt' ) ;
31
+ } ) ;
32
+
24
33
it ( 'transforms .php lang to .json' , ( ) => {
25
34
const lang = parse ( fs . readFileSync ( __dirname + '/fixtures/lang/en/auth.php' ) . toString ( ) ) ;
26
35
You can’t perform that action at this time.
0 commit comments