File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,13 @@ import path from 'path'
3
3
import { Engine } from 'php-parser'
4
4
import { ParsedLangFileInterface } from './interfaces/parsed-lang-file'
5
5
6
- const toCamelCase = ( str : string ) : string => str . replace ( / ^ \w / , ( c ) => c . toLowerCase ( ) )
6
+ const toCamelCase = ( str : string ) : string => {
7
+ if ( str === str . toUpperCase ( ) ) {
8
+ return str . toLowerCase ( )
9
+ }
10
+
11
+ return str . replace ( / ^ \w / , ( c ) => c . toLowerCase ( ) )
12
+ }
7
13
8
14
export const hasPhpTranslations = ( folderPath : string ) : boolean => {
9
15
folderPath = folderPath . replace ( / [ \\ / ] $ / , '' ) + path . sep
@@ -130,10 +136,12 @@ const parseItem = (expr) => {
130
136
let key = expr . key . value
131
137
132
138
if ( expr . key . kind === 'staticlookup' ) {
133
- key = toCamelCase ( expr . key . what . name )
134
- }
135
-
136
- if ( expr . key . kind === 'propertylookup' ) {
139
+ if ( expr . key . offset . name === 'class' ) {
140
+ key = toCamelCase ( expr . key . what . name )
141
+ } else {
142
+ key = toCamelCase ( expr . key . offset . name )
143
+ }
144
+ } else if ( expr . key . kind === 'propertylookup' ) {
137
145
key = toCamelCase ( expr . key . what . offset . name )
138
146
}
139
147
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class SomeClass
4
+ {
5
+ const NAME = 'name ' ;
6
+ }
7
+
8
+ return [
9
+ SomeClass::class => 'Some Class ' ,
10
+ SomeClass::NAME => 'Name ' ,
11
+ ];
Original file line number Diff line number Diff line change @@ -134,6 +134,13 @@ it('transforms enum values to .json', () => {
134
134
expect ( lang [ 'status.finished' ] ) . toBe ( 'Finished' ) ;
135
135
} ) ;
136
136
137
+ it ( 'transforms class names and consts to .json' , ( ) => {
138
+ const lang = parse ( fs . readFileSync ( isolatedFixtures + '/lang/en/classnames.php' ) . toString ( ) ) ;
139
+
140
+ expect ( lang [ 'someClass' ] ) . toBe ( 'Some Class' ) ;
141
+ expect ( lang [ 'name' ] ) . toBe ( 'Name' ) ;
142
+ } ) ;
143
+
137
144
it ( 'ignores empty `array` or `null` translations' , ( ) => {
138
145
const lang = parse ( fs . readFileSync ( isolatedFixtures + '/lang/en/ignore.php' ) . toString ( ) ) ;
139
146
You can’t perform that action at this time.
0 commit comments