rmariuzzo / laravel-localization-loader

Laravel Localization loader for webpack. Convert Laravel Translation strings to JavaScript Objects.
MIT License
70 stars 7 forks source link

Can't use class constants in the messages.php file #4

Open wijourdil opened 6 years ago

wijourdil commented 6 years ago

Hi ! The plugin works like a charm ! But I can't use class constants in the translations files, for example :

'status' => [
    MyClass::STATUS_WAITING => 'Lorem Ipsum',
    MyClass::STATUS_DONE => 'Dolor sit amet',
    ...,
]

I get the following error :

Module build failed: Error: Unexpected PHP key: "staticlookup
rmariuzzo commented 6 years ago

That's an interesting case. Not sure how easy will be to solve this case using JS.

ichiriac commented 6 years ago

Hi @rmariuzzo,

In order to address this kind of issue you have to scan and index class constants from every php into the repository, and also resolve the use statement in order to have a fully qualified class name (by resolving for example aliases).

I've tried something here : https://github.com/glayzzle/php-reflection but the library is not finished. You can maybe reuse some parts of code.

Best Regards, Ioan

rmariuzzo commented 6 years ago

@ichiriac that sound interesting, will take a look. I appreciate the details to avoid common pitfalls.