This repository was archived by the owner on Jul 16, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -44,13 +44,36 @@ private function allocateLocaleArray($path)
44
44
foreach ($ dir as $ fileinfo ) {
45
45
if (!$ fileinfo ->isDot ()) {
46
46
$ noExt = $ this ->removeExtension ($ fileinfo ->getFilename ());
47
- $ data [$ noExt ] = include ($ path . '/ ' . $ fileinfo ->getFilename ());
47
+ $ tmp = include ($ path . '/ ' . $ fileinfo ->getFilename ());
48
+ $ res = [];
49
+
50
+ foreach ($ tmp as $ key => $ val ) {
51
+ $ res [$ key ] = $ this ->adjustString ($ val );
52
+ }
53
+
54
+ $ data [$ noExt ] = $ res ;
48
55
}
49
56
}
50
57
51
58
return $ data ;
52
59
}
53
60
61
+ /**
62
+ * Turn Laravel style ":link" into vue-i18n style "{link}"
63
+ * @param string $s
64
+ * @return string
65
+ */
66
+ private function adjustString ($ s )
67
+ {
68
+ return preg_replace_callback (
69
+ '/:\w*/ ' ,
70
+ function ($ matches ) {
71
+ return '{ ' . mb_substr ($ matches [0 ], 1 ) . '} ' ;
72
+ },
73
+ $ s
74
+ );
75
+ }
76
+
54
77
/**
55
78
* @param string $filename
56
79
* @return string
Original file line number Diff line number Diff line change @@ -87,4 +87,39 @@ function testBasic()
87
87
88
88
$ this ->destroyLocaleFilesFrom ($ arr , $ root );
89
89
}
90
+
91
+ function testNamed ()
92
+ {
93
+ $ arr = [
94
+ 'en ' => [
95
+ 'help ' => [
96
+ 'yes ' => 'see :link y :lonk ' ,
97
+ ]
98
+ ],
99
+ 'sv ' => [
100
+ 'help ' => [
101
+ 'yes ' => 'se :lonk a :link ' ,
102
+ ]
103
+ ]
104
+ ];
105
+
106
+ $ root = $ this ->generateLocaleFilesFrom ($ arr );
107
+
108
+ $ this ->assertEquals (
109
+ 'export default { ' . PHP_EOL
110
+ . ' "en": { ' . PHP_EOL
111
+ . ' "help": { ' . PHP_EOL
112
+ . ' "yes": "see {link} y {lonk}" ' . PHP_EOL
113
+ . ' } ' . PHP_EOL
114
+ . ' }, ' . PHP_EOL
115
+ . ' "sv": { ' . PHP_EOL
116
+ . ' "help": { ' . PHP_EOL
117
+ . ' "yes": "se {lonk} a {link}" ' . PHP_EOL
118
+ . ' } ' . PHP_EOL
119
+ . ' } ' . PHP_EOL
120
+ . '} ' . PHP_EOL ,
121
+ (new Generator )->generateFromPath ($ root ));
122
+
123
+ $ this ->destroyLocaleFilesFrom ($ arr , $ root );
124
+ }
90
125
}
You can’t perform that action at this time.
0 commit comments